我的Spring3应用程序运行良好。基本上客户端想要将db从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;
有人可以帮助我吗?
答案 0 :(得分:1)
如果要将其与Oracle
一起使用,请添加此注释@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="my_entity_seq_gen")