休眠中的JPA bigdecimal问题
我已经使用了 hibernate 的 maven 插件,它生成了实体类,但没有识别与 ID 字段相关的序列,id 字段生成为 BigDecimal...现在即使我通过代码指向现有序列,例如..
@Entity
@javax.persistence.SequenceGenerator(
name = "SEQ_NATUREMASTER", sequenceName = "aop_teqachers_school_nature_id_seq")
@Table(name = "aop_teachers_school_nature_master", schema = "public", uniqueConstraints = @UniqueConstraint(columnNames = "school_nature"))
public class AopTeachersSchoolNatureMaster implements java.io.Serializable {
/**
* Above code is added after generating entity class
*/
private BigDecimal id;
并且我得到了错误
INFO : aop.web.teacher.controller.SchoolMasterInsertController - Attemped saving!testnature
Hibernate: select nextval ('aop_teqachers_school_nature_id_seq')
Dec 14, 2010 6:57:26 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet appServlet threw exception
org.hibernate.id.IdentifierGenerationException: this id generator generates long, integer, short or string
at org.hibernate.id.IdentifierGeneratorHelper.get(IdentifierGeneratorHelper.java:123)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:101)
at org.hibernate.id.SequenceHiLoGenerator.generate(SequenceHiLoGenerator.java:81)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:122)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:69)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:154)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:110)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:650)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:624)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:628)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:308)
I have used maven plugin for hibernate and it has generated entity classes without identifing sequences that are related to ID fields, id fields are generated as BigDecimal... now even if I point to an existing sequence through code like..
@Entity
@javax.persistence.SequenceGenerator(
name = "SEQ_NATUREMASTER", sequenceName = "aop_teqachers_school_nature_id_seq")
@Table(name = "aop_teachers_school_nature_master", schema = "public", uniqueConstraints = @UniqueConstraint(columnNames = "school_nature"))
public class AopTeachersSchoolNatureMaster implements java.io.Serializable {
/**
* Above code is added after generating entity class
*/
private BigDecimal id;
and I am getting error
INFO : aop.web.teacher.controller.SchoolMasterInsertController - Attemped saving!testnature
Hibernate: select nextval ('aop_teqachers_school_nature_id_seq')
Dec 14, 2010 6:57:26 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet appServlet threw exception
org.hibernate.id.IdentifierGenerationException: this id generator generates long, integer, short or string
at org.hibernate.id.IdentifierGeneratorHelper.get(IdentifierGeneratorHelper.java:123)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:101)
at org.hibernate.id.SequenceHiLoGenerator.generate(SequenceHiLoGenerator.java:81)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:122)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:69)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:154)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:110)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:650)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:624)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:628)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:308)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不会选择十进制 ID。而且我真的认为您也不需要 BigInteger。因此将其更改为
int
或long
。 (失败的原因是序列无法生成类型BigX
)I wouldn't go for a decimal ID. And I really don't think you'd need
BigInteger
either. So change it toint
orlong
. (The reason this fails is that the sequence can't generate the typesBigX
)