-->
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: Hibernate Session help
PostPosted: Thu Aug 02, 2007 8:08 pm 
Newbie

Joined: Thu Aug 02, 2007 6:00 pm
Posts: 1
Hibernate Session Help.

I am encountering a problem using the same session
for Retrieving multiple objects, but just committing
one object to the database. Here is a sample:

1-->
There are two Classes
* Person (id, Name, DOB) and
* Shop (id, Name, Location, PersonInCharge)

2-->
There is no relationship defined between these
two classes.

3-->
Open a new Hibernate Session

4-->
Load a Person (id=2) using the session

5-->
Change DOB format from database format (yyyy-MM-dd)
to a format Application understands (MM/dd/yyyy)

6-->
Using the same Session I am loading the Shop (id=1)
object

7-->
Begin a Transaction

8-->
Update shop object

9-->
Commit Transaction

When I commit the transaction in step 9, Hibernate
also updates the "Person" object that was updated
in step 5. This change was indented for application
usage and not to be committed into the database.

My question(s):

Why is hibernate automatically saving the data?

Isn't commit saying only commit the statements that
are part of a transaction?

Can I set hibernate configuration not to do this.

I have tried this example with autocommit set to
true and also to false and it behaves in the same way
in both cases.

My work-around:
I figured out a work-around (which I don't like much
and thats' the reason I am posting this...). If I open
a new session and do the update for the Shop object,
the Person object changes are ignored.

Thank you for any help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 12:00 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
Any object loaded by hibernate that has state changes is updated by hibernate when it commits.

To avoid it you have to evict it from the session by doing session.evict(object).

_________________
Don't forget to rate the reply if it helps..:)

Budyanto


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.