gpt4 book ai didi

java - Oracle 序列与 Hibernate

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:04:51 26 4
gpt4 key购买 nike

我的 Spring 3 应用程序进展顺利。基本上,客户希望将数据库从 MySQL 迁移到 Oracle。所以一切都是对的;问题是用Oracle的顺序提出来的。我尝试了各种配置 Hibernate 的方法,但总是出现错误

org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assi

gned before calling save():
org.hibernate.id.Assigned.generate(Assigned.java:52)
org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:117)
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:206)
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:191)
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:114)
org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:735)
org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:727)
org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:723)
it.openingcode.vwh.dao.AbstractHibernateDAOImpl.save(AbstractHibernateDAOImpl.java:48)
it.openingcode.vwh.dao.AbstractHibernateDAOImpl.save(AbstractHibernateDAOImpl.java:20)
it.openingcode.vwh.services.AbstractCrudServiceImpl.save(AbstractCrudServiceImpl.java:70)
it.openingcode.vwh.services.AbstractCrudServiceImpl.saveAll(AbstractCrudServiceImpl.java:77)
it.openingcode.vwh.services.PrivilegiServiceImpl.updateFromGruppo(PrivilegiServiceImpl.java:92)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:606)

在模型中我添加了如下注释:

    @Id
@GeneratedValue(strategy = GenerationType.AUTO, generator="my_entity_seq_gen")
@SequenceGenerator(name="my_entity_seq_gen", sequenceName="SEQ_PROFILI")
@Column(name = "ID")
private Long id;

最佳答案

如果你想在 Oracle 中使用它,请放置此注释

@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="my_entity_seq_gen")

关于java - Oracle 序列与 Hibernate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23511962/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com