-->
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: (Beginner): attaching pojo tot persistent parent
PostPosted: Fri Apr 11, 2008 3:33 am 
Newbie

Joined: Fri Apr 11, 2008 3:20 am
Posts: 3
Hi everybody,

(I'm very new to hibernate, so pls give me some credit here.)

Say I have an object P that has a list of childeren (A,B,C) in my DB.

The user clicked on P in the UI and now want to see its children.

So I fetch these objects from the database (on the server) and send them to the client (the session is closed on the server but persistent object P is kept in memory). The user deletes A and adds a new D. Next he clicks save.

On the server, can I just open a session, add the pojo D to (the persistent object, so the hibernate proxy around the real..) P and Update ? A collegae of mine says this will fail because I can not mix persistent objects and pojos. And save won't work either because P already exists. How is one to handle this ? Or are we missing something?

thanks a lot!

Best regards,
mrxjn

_________________
Don't eat yellow snow.


Top
 Profile  
 
 Post subject: Re: (Beginner): attaching pojo tot persistent parent
PostPosted: Fri Apr 11, 2008 10:06 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
It should be fine as long as D is a mapped entity.



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 11, 2008 10:37 am 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:04 am
Posts: 27
I'm afraid your colleage doesn't know what he is talking about.

http://www.hibernate.org/hib_docs/refer ... e-detached

explains how to modify objects that live longer than their session.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 11, 2008 10:50 am 
Newbie

Joined: Fri Apr 11, 2008 3:20 am
Posts: 3
thanks for your replies!


what my collegea means is...

// in the first session
Cat cat = (Cat) firstSession.load(Cat.class, catId);

// in the second session...
Cat potentialMate = new Cat();
cat.setMate(potentialMate);
secondSession.update(cat); // update cat

that this will not work

_________________
Don't eat yellow snow.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 11, 2008 10:51 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
but secondSession.merge(cat) will definitely do.



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 11, 2008 11:00 am 
Newbie

Joined: Fri Apr 11, 2008 3:20 am
Posts: 3
oki, so merge is the magical method :)

thanks a lot guys! I'll tell him on monday :)


thanks for your time!

_________________
Don't eat yellow snow.


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.