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.