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.
|