Hey guys,
At first, i'm using Hibernate version: 2.0.
I would like to change Data's in a "one-to-many"-Relationship. I have to mention, that the following example acts (!!!!) I'm implemention some test cases and the only question is why is the session not dirty?!
For example:
A Employee has more than one company car.
now i remove his first company car and add another one.
When i delete his first car out of the
list, the sessions gets dirty.
But when i do now a "createQuery"-Statement the sessions isn't dirty anymore. That is not logical to me!
What the hell i'm doing wrong? I need help. Thanks a lot!
my code:
Code:
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
User user = (User) session.createQuery( "from User u where u.name like 'testname'" ).list().get( 0 );
Car carToDelete = null;
for ( Car itCar : user.getCars() ) {
if ( itCar.getDescription().equals( "BMW 7" ) ) {
carToDelete = itCar;
}
}
user.getCars().remove( carToDelete );
now - session.isDirty() is true //that is accurate!!!
the next step i do is only...
Code:
Car newCar = (Car) session.createQuery( "from Car a where a.id = 2" ).list().get( 0 );
and then the
session.isDirty() is false!!! //that is NOT accurate
if i add this (other) car to the user like this......
Code:
user.getCars().add( newCar );
the session is dirty again //that is accurate!!!
so can somebody tell me why the session get "clean" after i perform a createQuery() ?
Thank you very much!