-->
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: cascade="save-update" or "persist"
PostPosted: Fri Mar 16, 2007 8:07 am 
Beginner
Beginner

Joined: Wed Mar 14, 2007 10:19 am
Posts: 24
Can please someone with me the difference between cascade="save-update" and cascade="persist"?I read the documentation but I do not really understand the difference.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 9:55 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
They refer to the corresponding methods in the Session API. persist is the JPA compliant method corresponding to save. (and merge is like update)
Using one cascade mode depends one which method you use persist or save

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 10:11 am 
Beginner
Beginner

Joined: Wed Mar 14, 2007 10:19 am
Posts: 24
Lets say I have a pojo named "Item" and it has a one-to-many relationship with a set named "bids"

I use in both of the xml mapping cascade="save-update" I guess that means that I can do:
Code:
session.save(item) and then item.setBids(bids)

If I had cascade="persist" what would be the difference?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 10:36 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Try and you will know :-)

For me persist is just the standard (JPA) way to say save (maybe there is some subtle differences).
If you use cascade="persiste then use session.persist() for your object instead of session.save().
I don't know if hibernate unifies the two thing internally. Maybe setting cascade="persist" and using session.save() is ok and has the same behaviour but it is not very coherent.
Maybe using persist instead of save is better because it is more standard. You can look at hibernate source code to see if save and persist are exactly the same or not.

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


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.