Stackoverflow occurred if composite id has many to one relationshipt.
See unit test in attached file.
hibernate-core: 3.3.0.SP1, hibernate-annotations: 3.4.0.GA
Hi,
If you happens to comment out session.evict() from the test it gets passed.
public void testBug() throws Exception {
Session session = sessionFactory.openSession();
try {
ClassA classA;
Transaction transaction = session.beginTransaction();
transaction.begin();
try {
classA = new ClassA();
List<ClassB> children = new ArrayList<ClassB>();
ClassB classB = new ClassB();
ClassBPK pk = new ClassBPK();
pk.setClassA(classA);
pk.setName(UUID.randomUUID().toString());
classB.setClassBPK(pk);
children.add(classB);
classA.setChildren(children);
session.persist(classA);
} catch (Exception e) {
transaction.rollback();
throw e;
}
transaction.commit();
session.evict(classA);// commenting out this lines makes the test passed.
session.get(ClassA.class, classA.getId());
} catch (Exception e) {
session.close();
throw e;
}
}
As per the documentation of evict() method, it will remove the associated object from the session cache. So in your next line session.get(ClassA.class, classA.getId()) you are trying to get an object from session which is already removed from session.
The commented line is not solution to resolve the issue,