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.  [ 1 post ] 
Author Message
 Post subject: saveOrUpdate() - why does it return void and not like save()
PostPosted: Wed Dec 21, 2011 1:07 pm 
Newbie

Joined: Wed Dec 21, 2011 12:56 pm
Posts: 3
I have a distributed System in which the Client can create some new Entities.
Those Entities by default have no Identifier so I call a remote Method of my Application Server to save the Object to Hibernate.
As a return the Client receives the positive Identifier on success and can set it and so the client made sure the Server App has saved the Object.
Else no Client Entity-Object would be created.

This is realized with a method which is called from the remote bean:

Code:
public int saveObj(Obj obj)
{
    //...
    return (Integer)session.save(obj);
}



This works fine aslong I know that the object is new.

Now I have a Entity with some relations so that I need to save or update some relational Entities.
But i cannot receive the id anymore since saveOrUpdate() returns void.

I maybe could return the saved Object, but that would be much more overhead instead of an primitive int, or I would need a cast to the specific Entity to return the identifier field. Or use reflection.


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

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.