在grails / hibernate中使用uuid或guid作为id [英] Using an uuid or guid as id in grails/hibernate
问题描述
我需要将GUID / UUID作为行的id列。
这可以在线和离线创建条目,当然不能合并时在PK上产生这些冲突。我知道我可以减轻这一点,但我想保持简单,并且已有的应用程序已经使用uuid / guid来定义关系)。之后数据也需要同时双向同步。重写现有的应用程序不是一个选项。
当我尝试在Grails中使用GUID或UUID时,出现错误500.(在h2上使用GUID导致另一个错误 - 如预期那样,DB不支持GUID)。
当我尝试保存'WithUUID'时出现此错误:
URI / gtestUUID / withUUID / save
类java.lang.IllegalArgumentException
消息参数类型不匹配
整个错误500:
http://imgur.com/m2Udbm6.png
我尝试过使用mariadb 5.5和1.1.7驱动程序,导致同样的问题。
Grails 2.3.8。 Windows 8.1(x64)。 Netbeans 7.4
全部默认。
示例类:
WithUUID.groovy:
包gtestuuid
类WithUUID {
字符串名称
static constraints = {
}
static mapping = {
id generator:'uuid'
}
}
WithUUIDController.groovy:
package gtestuuid
class WithUUIDController {
def scaffold = WithUUID
}
任何帮助将不胜感激。
(我无法发布链接到更多文档/我的低代表)
您需要将ID设置为String或UUID(或任何您需要的)。
下面是我的另一个类User的例子:
import java.util.UUID
class User {
String id = UUID.randomUUID()。toString()
static mapping = {
id生成器:'分配'
}
}
I need to have GUID/UUID's as the id column of my rows.
This is to be able to create entries both online and offline, and of course not having these conflict on PK when merging. I know i could mitigate this, but i'd like to keep it simple, and there is legacy apps already using uuid/guids to define relationships). Data also needs to be synced both ways later. Rewriting existing applications is not an option.
When i try to use either GUID or UUID with grails i get an error 500. (using a GUID on h2 results in another error - detaling that DB does not support GUIDs, as expected).
I get this error when i try to save an 'WithUUID':
URI /gtestUUID/withUUID/save
Class java.lang.IllegalArgumentException
Message argument type mismatch
Entire Error 500: http://imgur.com/m2Udbm6.png
I've tried with mariadb 5.5 and 1.1.7 driver, this results in the same problem.
Grails 2.3.8. Windows 8.1 (x64). Netbeans 7.4
all default.
Example classes:
WithUUID.groovy:
package gtestuuid
class WithUUID {
String name
static constraints = {
}
static mapping = {
id generator: 'uuid'
}
}
WithUUIDController.groovy:
package gtestuuid
class WithUUIDController {
def scaffold = WithUUID
}
Any help would be greatly appreciated.
Link to relevant grails documentation
(i'm not able to post links to more docs/posts due to my low rep)
You need to set the id as String or UUID (or anything you need).
Below, an example of my class User with another possibility:
import java.util.UUID
class User {
String id = UUID.randomUUID().toString()
static mapping = {
id generator:'assigned'
}
}
这篇关于在grails / hibernate中使用uuid或guid作为id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!