-->
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.  [ 4 posts ] 
Author Message
 Post subject: Session is not dirty although i changed an Object
PostPosted: Tue Feb 22, 2005 11:12 am 
Newbie

Joined: Tue Feb 22, 2005 10:39 am
Posts: 7
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!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 22, 2005 11:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Before a query, Hibernate performs a flush()


Top
 Profile  
 
 Post subject: i forgott the mapping
PostPosted: Tue Feb 22, 2005 11:19 am 
Newbie

Joined: Tue Feb 22, 2005 10:39 am
Posts: 7
sorry i have forgotten to write the mapping


Code:
mapping for User-class:

<class name="User" table="ML_USER">
      <id name="id" column="ID" type="int">
         <generator class="increment"/>
      </id>
      <property name="name" column="NAME" not-null="false"/>
        <set name="cars" lazy="true" table="ML_CARS" inverse="false" cascade="all">
            <key column="USER_ID"/>
            <one-to-many class="Car"/>
        </set>
</class>

mapping for the car-class:

<class name="Car" table="ML_CARS">
        <id name="id" column="ID" type="int">
            <generator class="increment"/>
        </id>
        <property name="description" column="DESCRIPTION" not-null="false"/>
        <property name="ps" column="PS" not-null="false"/>
</class>



Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 22, 2005 11:41 am 
Newbie

Joined: Tue Feb 22, 2005 10:39 am
Posts: 7
michael wrote:
Before a query, Hibernate performs a flush()


thank you!


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