-->
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.  [ 4 posts ] 
Author Message
 Post subject: Possible error in book?
PostPosted: Thu May 21, 2009 2:16 pm 
Beginner
Beginner

Joined: Wed Nov 12, 2008 12:07 pm
Posts: 21
Hello
In page 712 of Java Persistence with Hibernate, in the GenericHibernateDAO, if you are meant to return the persisted entity shouldn't you do:
Code:
public T makePersistent(T entity) {
       entity = (T) getSession().saveOrUpdate(entity);
        return entity;
    }
?


Top
 Profile  
 
 Post subject: Re: Possible error in book?
PostPosted: Thu May 21, 2009 4:36 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Of course not, because saveOrUpdate() is return type void.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Re: Possible error in book?
PostPosted: Fri May 22, 2009 9:15 am 
Beginner
Beginner

Joined: Wed Nov 12, 2008 12:07 pm
Posts: 21
Sorry, merge/saveOrUpdate confusion!

How can I overcome the problem of persisting 2 objects of same class that has an association with a third object of other class (with cascade) without creating 2 rows for this third object?


Top
 Profile  
 
 Post subject: Re: Possible error in book?
PostPosted: Fri May 22, 2009 9:42 am 
Beginner
Beginner

Joined: Wed Nov 12, 2008 12:07 pm
Posts: 21
I mean, I had to use merge() because of the NonUniqueObjectException problem (because I have a client - outside of JBoss - using the EJB DAO in JBoss, so session is always closed after the method execution), but now I have this problem since merge() returns a new instance of the persisted object and the second object still points to the old-non-persisted instance of the object.


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