Hi,
I have two classes A and B, A is the parent Class and B is extending A. In my DAO class, I am trying to persist B i.e. session.save(objB). Internally Hibernate is firing two insert statements i.e. one for A and another for B. So My issue is : I am passing one of the variable in B object as NULL, where database will not allow to insert into B table. When i am persisting the Same Object i.e. session.save(objContainingNULLB).
When i do session.flush, Hibernate is inserting into A successfully and throwing exception at insert into B Table (saying Cannot insert null). I am doing session.clear() in catch block, It is not removing the successful insert object i.e. A.
And after all inserts, i am having transaction.commit() i.e. I am following Single Transaction mechanism i.e. for multiple insert only one transaction i am using. Before For loop, i am starting the transaction and after For loop, I am committing the transaction.
So the value is inserting successfully into A without inserting into B.
Can you please tell, how can i avoid this situation. Whether Hibernate will not rollback internally?
Thanks in advance, Vishal
|