[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2712?page=c...
]
Chris Federowicz commented on HHH-2712:
---------------------------------------
I had the same problem and found a solution that worked for me here:
http://www.i-proving.ca/space/Technologies/Hibernate/Hibernate+Annotation...
The key for me was the PK mapping for the secondary entity:
@Id @GeneratedValue(generator="foreign")
@GenericGenerator(name="foreign", strategy = "foreign",
parameters={
@Parameter(name="property", value="person")
})
public Long getId() {
return this.id;
}
In their example, Person is the primary entity and Patient is the secondary. Basically I
just took these annotations and changed "person" to the property name of my own
OneToOne mapping back to my primary entity.
OneToOne mapping with PrimaryKeyJoinColumn and CascadeType.ALL throws
IdentifierGenerationException
---------------------------------------------------------------------------------------------------
Key: HHH-2712
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2712
Project: Hibernate3
Issue Type: Bug
Environment: Hibernate 3.2.4, Annotations 3.3.0
Reporter: Colin Smith
Customer has a 1-1 mapping with CustomerRiskProfile.
@Id
@GeneratedValue(strategy = GenerationType.TABLE, generator =
"SEQUENTIAL_HILO_GENERATOR")
private Long id;
@OneToOne(cascade = CascadeType.ALL)
@PrimaryKeyJoinColumn
private CustomerRiskProfile customerRiskProfile;
CustomerRiskProfile has:
@Id
private Long id;
@OneToOne(mappedBy = "customerRiskProfile")
private Customer customer;
If I create a new Customer and a new CustomerRiskProfile, associate the two, then call
session.save(customer), I get:
org.springframework.orm.hibernate3.HibernateSystemException: ids for this class must be
manually assigned before calling save(): com.cantorcfds.domain.CustomerRiskProfile; nested
exception is org.hibernate.id.IdentifierGenerationException: ids for this class must be
manually assigned before calling save(): com.cantorcfds.domain.CustomerRiskProfile
Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be
manually assigned before calling save(): com.cantorcfds.domain.CustomerRiskProfile
at org.hibernate.id.Assigned.generate(Assigned.java:33)
at
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
at org.hibernate.engine.CascadingAction$1.cascade(CascadingAction.java:218)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at
org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:456)
at
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:334)
at
org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:495)
at
org.springframework.orm.hibernate3.HibernateTemplate$16.doInHibernate(HibernateTemplate.java:689)
at
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)
at
org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:686)
at com.cantorcfds.dao.HibernateCustomerDao.save(HibernateCustomerDao.java:36)
at com.cantorcfds.domain.TestSchemaLoad.testDataLoad(TestSchemaLoad.java:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
I would expect Hibernate to generate the Id for the Customer AND the CustomerRiskProfile
before trying to save anything?
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira