休眠中的JPA bigdecimal问题

发布于 2024-10-07 05:45:03 字数 2101 浏览 4 评论 0原文

我已经使用了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〃安静 2024-10-14 05:45:03

我不会选择十进制 ID。而且我真的认为您也不需要 BigInteger。因此将其更改为 intlong。 (失败的原因是序列无法生成类型 BigX

I wouldn't go for a decimal ID. And I really don't think you'd need BigInteger either. So change it to int or long. (The reason this fails is that the sequence can't generate the types BigX)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文