-->
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.  [ 2 posts ] 
Author Message
 Post subject: TransientObjectException for CascaseType.ALL
PostPosted: Tue Aug 09, 2011 4:54 pm 
Newbie

Joined: Tue Aug 09, 2011 4:46 pm
Posts: 2
Hello,

I got a very straightforward bi-directional mapping that's deployed to JBoss 6.0.0.Final (Hibernate 3.6.0.Final) as a JPA PU:

Code:
Convocation 1 <---> 0..* GraduandDetail 1 <---> 1 Student:


Here is the code:

Code:
@Entity
public class Convocation implements Serializable{
   ...
   @OrderBy("acrossStageNumber")
   @OneToMany(mappedBy = "convocation", cascade = {CascadeType.ALL})
   private List<GraduandDetail> graduandDetails = new ArrayList<GraduandDetail>();
   ...
}

@Entity
public class GraduandDetail implements Serializable {
   ...
   @ManyToOne
   @JoinColumn(name = "convocation_fk", referencedColumnName="id")
   private Convocation convocation;
   private Integer acrossStageNumber;
   ...
   @OneToOne(cascade = CascadeType.ALL)
   @PrimaryKeyJoinColumn
   private Student student;
}

@Entity
public class Student implements Serializable {
   ...
   private String name;
   @OneToOne(mappedBy="student")
   private GraduandDetail graduandDetail = new GraduandDetail(this);
   ...
}


After I add new students to a persistent convocation instance and then call EntityManager.merge(convocation), I expect Hibernate to merge the convocation instances along with the changes to the underlying graduands collection. However, I end up having a org.hibernate.TransientObjectException, with some prior tests, I also saw duplicate student entries in the database:

Quote:
Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: ca.mcmaster.registrar.convocation.model.Student.graduandDetail -> ca.mcmaster.registrar.convocation.model.GraduandDetail
at org.hibernate.engine.CascadingAction$9.noCascade(CascadingAction.java:387) [:3.6.0.Final]
at org.hibernate.engine.Cascade.cascade(Cascade.java:172) [:3.6.0.Final]


Can you please be so kind to point the RTFM section of the Hibernate manual. I am out of clues now...

Thank you kindly.


Top
 Profile  
 
 Post subject: Re: TransientObjectException for CascaseType.ALL
PostPosted: Wed Aug 10, 2011 9:31 am 
Newbie

Joined: Tue Aug 09, 2011 4:46 pm
Posts: 2
I guess this is too advanced for the Hibernate folks :). Anyhow, I gave up trying to enable cascading. So I ended up removing the cascading option altogether from the Convocation class, and now persist the GraduandDetails manually, when I persist a Convocation instance. This seemed to work like charm:

Code:
for (Convocation convocation : convocationCycle.getConvocations()) {
   for (GraduandDetail details : convocation.getGraduandDetails())
      dao.save(details);
   dao.merge(convocation);
   dao.flush();
}


DAO here is just a placeholder for EntityManager here.

Oh, and it looks like the RTFM section is this, although I am still not sure as to why the exception occurs:

http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#example-parentchild

Altogether, I didn't touch Hibernate for a little while, but it seems to be a ton more flaky than it was at 2.x times...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.