hello good fellas! i use spring and hibernate for my data access layer i'll like to have some guidance about how to construct my unit testing to test if hibernate is effectively insert in the child table(parent hibernate mapping has the cascade all on the set). For what i know i shouldn't mix dao's unit testing.So supposing the i'm testing the Parent DAO methods saveWithChild:
public void testSaveWithChild() {
Child c1 = new Child("prop1", "prop2", prop3);
Child c2 = new Child("prop4", "prop4", prop3);
Parent p = new Parent("prop6","prop7");
p.addChild(c1);
p.addChild(c2);
Session session = MysessionImplementation.getSession();
Transaction tx = session.begingTransaction();
ParentDAO.saveWithChild(p);
tx.commit();
Session session1 = MysessionImplementation.getSession();
//now it is right to call child table in here?
Child c1fromdb = (Child)session1.get(ChildClass.class,c1.getID());
Child c2fromdb = (Child)session1.get(ChildClass.class,c2.getID());
//parent asserts goes here
//children asserts goes here.
}
I don't know but i don't feel confortable doing this.Isn't there any better way? How will you check those things? thanks for reading. ;)