As both have one to many relation so i have declared a set in Category Table.
i have also described the relation in Category.hbm.xml file
And in Product i have made
and in Product.hbm.xml file i have set
I have created the object of Category and put the objects of products in it. When i execute session.Save(catObj) method It throws exception. It execute the insert query of Category but for product it execute the Update query. Why? what i am doing wrong?
I had encountered the same error when I was experimenting with Hibernate and MS SQL Server. The problem in my application was caused by JTDS driver and by the fact that the referential integrity was maintained using _triggers_. JTDS driver returns bad value of count of rows affected by insert (it is caused by trigger or bug in driver or both . So in my case the inserting was _successful_, but the zero value returned by executeUpdate caused a HibernateException (see source of NonBatchingBatcher), rollback of Hibernate transaction and rollback of JDBC transaction. After upgrading driver to 0.8.1 the problem disappeared. There is another advice in Hibernate FAQ based on setting the lastUpdateCount parameter, but it didn't help me. Anyway I recommend you to launch SQL insert in a small java-JDBC program without using Hibernate, it helped me a lot to locate the problem.
Hope this helps Tomas [ August 11, 2004: Message edited by: Tomas Zalusky ]
Hi all, I have exacly the same problem. I use Oracle database (9i) and for the fisrt time i create an object with a list attribute, hibernate generates an update instead of a create !! i hope that since the 1st post, someone has found the solution
I am getting same problem while using Hibernate from Spring Framework. I have Position to Employee as one to many relationship.It is giving me same exception when i try to insert positions from Employee objects.I had tried all option like cascade="save-update" and cascade="all". Can somebody help me!!
Originally posted by Arpit Todi: I am getting same problem while using Hibernate from Spring Framework. I have Position to Employee as one to many relationship.It is giving me same exception when i try to insert positions from Employee objects.I had tried all option like cascade="save-update" and cascade="all". Can somebody help me!!
posted 15 years ago
Hi everyone, I am also facing the same problem. An insert statement is executed for a parent record whereas an update statment for a child record. If any one has solved it pls reply. Itz very urgent. Thanx in advance