在用hibernate生成主键时候
对应字符类型主键
我采用uuid.string
因为表里长度是20,结果服务启动时候报如下错误:
Error creating bean with name 'sessionFactory ' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingException: could not instantiate id generator
org.hibernate.MappingException: could not instantiate id generator
奇怪的是,改成uuid.hex就没有问题
页面运行时候,id正常生成了
请问,是什么原因
------解决方案--------------------
你的数据库不支持那个 generator 类型吧
------解决方案--------------------
我也没有遇到过这种问题。
baidu 了一下 找到下面两个区别看对你是否有帮助
uuid.hex
hibernate会算出一个128位的唯一值插入
uuid.string
hibernate会算出一个16位的值插入
原文地址 http://blog.csdn.net/nsrainbow/archive/2008/04/19/2307687.aspx
------解决方案--------------------
在hibernate2.1中,主键生成策略中uuid分为uuid.hex和uuid.string,但是从hibernate3.0开始已经不再支持uuid.string,查看changelog可以发现:
Changes in version 3.0 beta 1 (21.12.2004)
* removed uuid.string and renamed uuid.hex to plain uuid
hibernate3.x的api中AbstractUUIDGenerator类只有UUIDHexGenerator子类了,
使用时在hibernate的映射文件中,配置成<generator class="uuid"/>;(其实写成uuid.hex也是可以用的,但官方的reference文档中是uuid,所以不推荐写成uuid.hex)
------解决方案--------------------
同楼上的
------解决方案--------------------
主键还是 identity 和 sequence 比较好!
------解决方案--------------------
------解决方案--------------------
hibernate3.0开始已经不再支持uuid.string
uuid.hex也挺好的