当前位置: 代码迷 >> Java Web开发 >> hibernate映射文件有关自增类型,String,精度的有关问题
  详细解决方案

hibernate映射文件有关自增类型,String,精度的有关问题

热度:4245   发布时间:2013-02-25 21:12:24.0
hibernate映射文件有关自增类型,String,精度的问题
<id name="userId" type = "java.lang.String">
  <column name ="userid" precision="22" scale="0"/>
  <generator class="increment" />
  </id>
上面是我的id映射关系,应该是有问题的,我的表里id是String类型的,我写了个注册的页面,点击注册后页面是跳转了,但是数据没有插入到数据库。
报下面的错,不想把类型改成integer,会很麻烦,
Caused by: org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.String
at org.hibernate.id.IdentifierGeneratorHelper.getIntegralDataTypeHolder(IdentifierGeneratorHelper.java:178)
at org.hibernate.id.IncrementGenerator.initializePreviousValueHolder(IncrementGenerator.java:121)
at org.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:67)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:122)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:705)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:693)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:689)
at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:685)
at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:1)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:405)
... 91 more

------解决方案--------------------------------------------------------
generator不能为increment的
  相关解决方案