Hi, The issue is as follows. I have a list of contacts associated with a supplier class. In database, it is mirrored by the contact table having supplier_id as foreign key. The add supplier works fine. But, when I try to update the supplier in a way that the list of contacts contains One contact to be be edited (it has an id). ANd one contact without id, there is a problem.
Hibernate inserts a new contact as expected, and updates the contact with id, but the supplier_id belonging to all other contacts in the database is set to zero. It must be sthign trivial !!!
Hibernate version:
3.1
Mapping documents:
<class name="SupplierDTO" table="supplier">
<set name="supplierContacts" cascade="all">
<key>
<column name="supplier_id"></column>
</key>
<one-to-many class="SupplierContactDTO" />
</set>
</class>
Code between sessionFactory.openSession() and session.close():
Session session = HibernateSession.getSessionFactory().openSession();
tx = session.beginTransaction();
session.saveOrUpdate(supplierObj);
session.flush();
tx.commit();
session.close();
Full stack trace of any exception that occurs:
Database corruped
Name and version of the database you are using:
mysql 5.0
The generated SQL (show_sql=true):
[junit] 2006-04-20 10:02:15,845 DEBUG [org.hibernate.SQL] insert into supplier_contacts (title, first_name, middle_name, last_name, phone_number, fax_number, email_address, language_id, contact_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
[junit] 2006-04-20 10:02:15,861 DEBUG [org.hibernate.SQL] update supplier set supplier_name=?, address_id=?, relationship_id=?, supplier_website=? where supplier_id=?
[junit] 2006-04-20 10:02:15,874 DEBUG [org.hibernate.SQL] update supplier_contacts set title=?, first_name=?, middle_name=?, last_name=?, phone_number=?, fax_number=?, email_address=?, language_id=? where contact_id=?
[junit] 2006-04-20 10:02:15,880 DEBUG [org.hibernate.SQL] update supplier_contacts set supplier_id=null where supplier_id=?
[junit] 2006-04-20 10:02:15,884 DEBUG [org.hibernate.SQL] update supplier_contacts set supplier_id=? where contact_id=?
[junit] 2006-04-20 10:02:15,887 DEBUG [org.hibernate.SQL] update supplier_contacts set supplier_id=? where contact_id=?
Debug level Hibernate log excerpt:
|