-->
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.  [ 2 posts ] 
Author Message
 Post subject: Saving and inserting objects
PostPosted: Thu Apr 08, 2004 7:54 pm 
Regular
Regular

Joined: Fri Mar 26, 2004 11:45 am
Posts: 75
Hi all.

I just barely started using Hibernate and ran into the following problem.

I have data, business, and presentation layers. Data layer classes are generated automatically and present simple "bean" classes. We then create business classes ourselves. Presentation layer calls query methods from the business classes. A session is opened and closed every time a business object method is executed. Also, business object just delegates method calls to the incapsulated data object.

The problem is with the save() method of the business class. I want this method to work with both persistent and newly created objects. However, if I use session.update(DO) it chockes on insertions, and if I use session.save(DO) it chokes on updates. When I try to use session.saveOrUpdate(DO) then if a table has a composite primary key it always tries to insert a new row, even if the object already persists in the database.

What is the right way to implement data/business/presentation architecture? Should I use different methods for saving persistent and newly created objects? If yes, then how can I determine whether an object persists in the database or not?

Thank you.

Oleg


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 7:56 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Check saveOrUpdate() in the API documentation and read up on the "unsaved-value" setting in the reference.

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


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