-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: TransientObjectException if both sides of 1:1 are set in tx
PostPosted: Sun Jul 16, 2006 3:25 am 
Newbie

Joined: Wed Mar 29, 2006 3:47 pm
Posts: 17
I am getting org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: IncidentStatus.incident -> Incident when I create two new entities and associate them with a OneToOne relationship inside the same transaction. My client code looks like this:

Code:
   emf = Persistence.createEntityManagerFactory("pu1");
   EntityManager em = emf.createEntityManager();
   em.getTransaction().begin();
   String id = args[0];
   Incident i = em.find(Incident.class, id);
   i = new Incident(id);
   IncidentStatus ist = new IncidentStatus(id);
   i.setIncidentStatus(ist);
   ist.setIncident(i);
   em.persist(i);
   em.getTransaction().commit();


If I don't call ist.setIncident(i); in the above code, it works.

Entity class definitions are supplied below.

Hibernate version: Hibernate EntityManager 3.2.0.CR1, Hibernate 3.2 cr3

Mapping documents:
Code:
@Entity public class Incident {
   @Id String id;

   @OneToOne(cascade=CascadeType.ALL)
   IncidentStatus incidentStatus;

   public Incident(){}

   public Incident(String id) { this.id = id; }

   public IncidentStatus getIncidentStatus() { return incidentStatus; }

   public void setIncidentStatus(IncidentStatus incidentStatus) {
       this.incidentStatus = incidentStatus;
   }

}

@Entity public class IncidentStatus {
   @Id String id;

   @OneToOne(mappedBy="incidentStatus")
   Incident incident;

   public IncidentStatus() {}

   public IncidentStatus(String id) { this.id = id; }

   public Incident getIncident() { return incident; }

   public void setIncident(Incident incident) { this.incident = incident; }

}


Full stack trace of any exception that occurs:
Exception in thread "main" javax.persistence.RollbackException: Error while commiting the transaction
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:63)
at Client.main(Client.java:22)
Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: IncidentStatus.incident -> Incident
at org.hibernate.engine.CascadingAction$9.noCascade(CascadingAction.java:273)
at org.hibernate.engine.Cascade.cascade(Cascade.java:257)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:130)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:121)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:53)
... 1 more

Name and version of the database you are using:
Derby


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 16, 2006 6:26 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Quote:
Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: IncidentStatus.incident -> Incident


That's exactly what it is.
It first tries to persist Incident, sees that it has an association - IncidentStatus - which has to cascade. But IncidentStatus again has association - Incident - which is really transient and unsaved.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 16, 2006 1:54 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hibernate EntityManager 3.2.0.CR1, Hibernate 3.2 cr3 should not work together anyway if I recall :-)

I can't reproduce on core 3.2.0.CR3 and Annotations HEAD

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 2:25 pm 
Newbie

Joined: Wed Mar 29, 2006 3:47 pm
Posts: 17
emmanuel wrote:
Hibernate EntityManager 3.2.0.CR1, Hibernate 3.2 cr3 should not work together anyway if I recall :-)


You are quite right. Those versions don't work together. I am building Hibernate core, entity manager and annotations from the source code that I checked out day before yesterday. I specified those wrong versions because that's what I see being printed by Hibernate run time in the console.

emmanuel wrote:
I can't reproduce on core 3.2.0.CR3 and Annotations HEAD

Have you tried reproducing using both core and annotations from HEAD? I am building both of them from HEAD.

Sahoo


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 4:35 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Yes I work with HEAD form core and annotations.
if you can attach your testcase to JIRA, I'll test it. Maybe I'm missing one of your config.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 6:20 am 
Newbie

Joined: Wed Mar 29, 2006 3:47 pm
Posts: 17
Attached test case to: http://opensource.atlassian.com/project ... se/EJB-206

Thanks,
Sahoo


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.