Hi,
I have a problem with 2 entities - a subclass (Person) that has a base class (SystemUser) with the JOINED Inheritance strategy.
I am using:
JBoss 4.2.2 GA, Hibernate version: 3.2.4 sp1, Hibernate EntityManager 3.2.1 GA
The Code:
Here is the code for each class:
Code:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class SystemUser implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
private String userName;
private HashedAuthenticationToken passphrase;
@Column(nullable=false,unique=true)
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
@OneToOne(cascade=CascadeType.ALL, mappedBy="principal")
public HashedAuthenticationToken getPassPhrase() {
return passphrase;
}
public void setPassPhrase(HashedAuthenticationToken passphrase) {
this.passphrase = passphrase;
}
public void setId(Long id) {
this.id = id;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
}
Code:
@Entity
public class Person extends SystemUser implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
private PersonRegistrationRequest creationRequest;
@OneToOne(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="person", optional=false)
public PersonRegistrationRequest getCreationRequest()
{
return creationRequest;
}
public void setCreationRequest(PersonRegistrationRequest creationRequest)
{
this.creationRequest = creationRequest;
}
@Column(nullable=false)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
In my DAO the relevant code is:
Code:
@PersistenceContext(unitName=SystemConstants.PERSISTENCE_CONTEXT_UNIT_NAME) EntityManager manager;
public Person savePerson(Person person){
return manager.merge(person);
}
At the time of calling savePerson, the person's Id is null, the person's name has a value, and the person's username and password also have values, although the Password's Id is null.
The person does have a reference to a an attached CreationRequest (it's Id is not null).
Quote:
Full stack trace of any exception that occurs:
16:18:25,640 ERROR [STDERR] org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.xyz.middleTier.entities.SystemUser
16:18:25,640 ERROR [STDERR] at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:219)
16:18:25,640 ERROR [STDERR] at org.hibernate.type.EntityType.getIdentifier(EntityType.java:397)
16:18:25,640 ERROR [STDERR] at org.hibernate.type.EntityType.replace(EntityType.java:253)
16:18:25,640 ERROR [STDERR] at org.hibernate.type.AbstractType.replace(AbstractType.java:153)
16:18:25,640 ERROR [STDERR] at org.hibernate.type.TypeFactory.replace(TypeFactory.java:515)
16:18:25,640 ERROR [STDERR] at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:377)
16:18:25,640 ERROR [STDERR] at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:179)
16:18:25,640 ERROR [STDERR] at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123)
16:18:25,640 ERROR [STDERR] at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:687)
16:18:25,640 ERROR [STDERR] at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:669)
16:18:25,640 ERROR [STDERR] at org.hibernate.engine.CascadingAction$6.cascade(CascadingAction.java:245)
16:18:25,640 ERROR [STDERR] at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
16:18:25,640 ERROR [STDERR] at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
16:18:25,640 ERROR [STDERR] at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
16:18:25,640 ERROR [STDERR] at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
16:18:25,640 ERROR [STDERR] at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:456)
16:18:25,640 ERROR [STDERR] at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:194)
16:18:25,640 ERROR [STDERR] at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:123)
16:18:25,640 ERROR [STDERR] at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:53)
16:18:25,640 ERROR [STDERR] at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
16:18:25,640 ERROR [STDERR] at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
16:18:25,640 ERROR [STDERR] at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
16:18:25,640 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:227)
16:18:25,640 ERROR [STDERR] ... 147 more
I really have tried to find out what is going on here on my own,
but this is really starting to hold up my project,
and It does seem to me that this should work - I do apologise for
polluting your forum if this turns out to be a real newbie question. :-)
Many thanks,
Kipster