Thanks for help, but that
was not actually the problem. I'm using MySQL database and should tell the database not to check the foreign key constraints for saving objects just for some time.
suppose I have A and B. B should have an A and A also should have a B. Suppose having this code:
Code:
sf.getCurrentSession().beginTransaction();
A a = new A();
B b = new B();
a.setB(b);
b.setA(a);
sf.getCurrentSession().save(a);
sf.getCurrentSession().save(b);
sf.getCurrentSession().commit();
This code will throw exception, because saving a will need a valid b, but b itself needs an a to be saved. Database will not allow me to save a without any b. Because of foreign key constraints.
This loop will make the problem.
I think this is not hibernate's problem, I should tell the database to do this, but by hibernate's help.
any idea?