-->
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: Is this a bug on load?
PostPosted: Fri Aug 11, 2006 10:19 am 
Newbie

Joined: Fri Jun 16, 2006 11:53 am
Posts: 12
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1.3

Mapping documents:
<class name="WheelManufacturer">
<id name="ID" type="long">
<generator class="native"/>
</id>
<property name="Name"></property>
</class>

<class name="WheelInstance">
<id name="ID" type="long">
<generator class="native"/>
</id>
<many-to-one name="WheelManufacturer" not-null="true" lazy="false" fetch="select"/>
<joined-subclass name="SixteenWheelManufacturer" table="SixteenWheelManufacturer">
<key column="ID"/>
<property name="StringValue"></property>
</joined-subclass>
</class>

<class name="CarMaker">
<id name="ID" type="long">
<generator class="native"/>
</id>
<property name="Name"></property>
<list lazy="false" fetch="select" name="WheelManufacturers">
<key column="cm_id"/>
<index column="idx"/>
<many-to-many column="wm_id" class="WheelManufacturer"/>
</list>
</class>

<class name="CompactCar">
<id name="ID" type="long">
<generator class="native"/>
</id>
<list lazy="false" fetch="select" name="CarMakers">
<key column="c_id"/>
<index column="idx"/>
<many-to-many column="cm_id" class="CarMaker"/>
</list>
<list lazy="false" fetch="select" name="WheelInstances">
<key column="c_id"/>
<index column="idx"/>
<many-to-many column="wm_id" class="WheelInstance"/>
</list>
</class>


Code between sessionFactory.openSession() and session.close():
Session session = sessionFactory.getCurrentSession();
Transaction transaction = null ;
try{
transaction = session.beginTransaction();
session.load(o, l);
transaction.commit();
}
catch( Exception e ) {
if(transaction != null)
transaction.rollback() ;
throw e ;
}
finally {
if(session.isOpen())
session.close();
}


Name and version of the database you are using: MySQL 5

The generated SQL (show_sql=true):

select, select, select, select, delete




My problem is the following. When I am loading an object, with 2 collections inside it, at the end, one of the collections related table gets a delete statement at the end. Now, to my understanding, there is no way, in a basic setup, a load should do a delete, right? More precisely, I am trying to load a compactCar, with 3 car makers in it, and no WheelInstances. The CarMakers table is the one who gets the delete statement at the end of the load, which leads to the CompactCar not having anything associated to it in the many-to-many table at the end of the load operation.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 11, 2006 11:18 am 
Newbie

Joined: Fri Jun 16, 2006 11:53 am
Posts: 12
As additionnal information, if I remove the unused collection WheelInstance, for one thing, the problem still happens. If I change the fetch mode to join, the problem still happens. If I go through criteria query instead, it still happens.

What baffles me is that the object is correctly persisted in the bd, but after the load operation, its collection is just gone from the DB. This leads me to believe the error is not a mapping one.

I searched the forums, and all I could find was comeone having a more or less similar problem in Hibernate 2, but no one ever anwsered him.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 11, 2006 12:28 pm 
Newbie

Joined: Fri Jun 16, 2006 11:53 am
Posts: 12
Some additionnal info:

-Collection set to lazy loading: still gets a delete statement
-The delete statement does not happen when the load is executed, but then the transaction.commit is executed.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 11, 2006 2:03 pm 
Newbie

Joined: Fri Jun 16, 2006 11:53 am
Posts: 12
In case anybody else ever has this problem, here is the solution:

The error was there was a bug in one of my setters. So, when hibernate would set the value, it would do so incorrectly, hence set nothing at all. Then, just before closing the session, hibernate, seeing the state of the object would not be what it should be in the database, would proceed to update the database with the 'modified' version, and delete the collection that was not set properly.

Evict would prevent hibernate from saving the object after it had loaded, as would
<property name="hibernate.connection.autocommit">false</property>


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.