I am noticing a weird behavior when I perform some basic checks using objects that have been .initialize()'ed using Hibernate.
The following 'if condition' fails even when it is supposed to pass:
for (int j = 0; j < trcList.size(); j++) { if (trcList.get(j).getABC().getId() == abc.getId()) { //do something break; } } However if I change it slightly, it passes where expected. In the snippet below, I grab the LHS value in a local variable and use that for comparison:
for (int j = 0; j < trcList.size(); j++) { int x = trcList.get(j).getABC().getId(); if (x == abc.getId()) { //do something break; } } trcList is an ArrayList created from an array of objects grabbed from a database using hibernate. Various fields in those objects including 'ABC' have been Hibernate.initialize()'ed.
Session session = null; try { session = HibernateUtil.initializeHibernateConnection(session); Criteria cr = ... //specify search criteria List results = cr.list(); TRC[] trcArray = new TRC[results.size()]; for (int i = 0; i < results.size(); i++) { trcArray[i] = (TRC) results.get(i); if (trcArray[i].getABC() != null) { Hibernate.initialize(trcArray[i].getABC()); } } session.getTransaction().commit(); return trcArray; } catch (RuntimeException re) { log.error("get failed", re); throw re; }
getID()return?