-->
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.  [ 3 posts ] 
Author Message
 Post subject: saveOrUpdate(Obj) question
PostPosted: Sat Oct 30, 2004 2:35 am 
Newbie

Joined: Thu Oct 28, 2004 3:38 am
Posts: 8
Is there a reason saveOrUpdate(Obj) doesn't return the new Id of the object submitted? I'm often at a point where I don't know if the Entity I'm persisting is new or not, but I do need to know it's Id value after I've submitted it. I'm putting near identical versions of the following code in a lot of places:

Code:
   if (Entity.isNew()) return session.save(Entity);
   session.update(Entity);
   return Entity.get(Id);


Is there anything wrong with this line of thinking? If there's not how do I pass a request to change it on to the development team?

-James


Top
 Profile  
 
 Post subject: correction
PostPosted: Sat Oct 30, 2004 2:37 am 
Newbie

Joined: Thu Oct 28, 2004 3:38 am
Posts: 8
Actually,
I just realized what changing the method signature would do to anybody who had subclassed session class, so forget about the getting it changed part - just let me know if the code above is OK to use.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 30, 2004 2:49 am 
Regular
Regular

Joined: Sat Aug 28, 2004 4:15 pm
Posts: 61
saveOrUpdate uses your unsaved-value-strategy to determine if you entity is persistent or transient.

If your whole goal is to always have your ID returned to you when persisting your objects, use saveOrUpdate but the immediately flush the session so the DML is actually sent to the DB. Then, you should be able to get the ID of the entity.

Either way, it seems as though you're doing some things different in your code compared to what you're saying you wanted to have happen.

_________________
Joe W


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