Sunday, January 13, 2013

Known Issues/Resolutions in upgrading to Hibernate 3.6.0


  • SELECT COUNT returns Long instead of Integer as of Hibernate 3.2, to align with JPA spec. See "Changed aggregation (count, sum, avg) function return types" within Hibernate Guide for info (it also shows how you can override the new behavior with Hibernate 3.1 behavior, but this is not recommended unless an appropriate amount of time is available).
  • org.hibernate.AssertionFailure: no collection snapshot for orphan delete ... Not 100% clear on the cause of this one. Research indicated something to do with a collection being mutable. This appears to happen when performing a HibernateCallback via Hibernate's execute() method. It looks like Hibernate tries to flush the cache during the execute() call, which is where this mutable topic gets thrown in. For the place where this was initially found it was for a SELECT, so when comparing with a HibernateCallback that did work, we found that changing the execute() to an executeFind() resolved the issue (assuming that execute() had to presume you were going to write data, and executeFind is read-only so a flush is not necessary). We tried to identify the root cause, but none of our hypotheses held up. More understanding on this issue would be good. See the fix as below:    
     BEFORE FIX:    
    List<Measurement> mesurementList = (List<Measurement>) getIAFHibernateTemplate().execute(hibernateCallback);


    AFTER FIX:
    List<Measurement> mesurementList = (List<Measurement>) getIAFHibernateTemplate().executeFind(hibernateCallback);

  • The object alias is also part of the return scalar array. The read order of the scalar array that is returned should account for this object aliases position. Refer to the fix below:    
    BEFORE FIX:    
    equipment = (Equipment)equipmentsDataArr[5];            
    equipment.setActiveInd((String)equipmentsDataArr[0]);        
    equipment.setDeviceTypeId((Integer)equipmentsDataArr[1]);    
    equipment.setDeviceNumber((String)equipmentsDataArr[2]);    
    equipment.setOrganizationAccountId((Integer)equipmentsDataArr[3]);    
    equipment.setLicenseTypeId((Integer)equipmentsDataArr[4]);

    AFTER FIX:
   equipment = (Equipment)equipmentsDataArr[0];    
    equipment.setActiveInd((String)equipmentsDataArr[1]);    
    equipment.setDeviceTypeId((Integer)equipmentsDataArr[2]);    
    equipment.setDeviceNumber((String)equipmentsDataArr[3]);    
    equipment.setOrganizationAccountId((Integer)equipmentsDataArr[4]);
    equipment.setLicenseTypeId((Integer)equipmentsDataArr[5]);


  • java.lang.ClassCastException: java.lang.String incompatible with java.lang.Character. For Hibernate projections when restrictions are added if the database column is of CHAR type then for adding the restrictions, we need to denote the CHAR in Java instead of String. Refer to the fix below:
    BEFORE FIX:
    criteria.add(Restrictions.eq("deleted", "N"));
    criteria.add(Restrictions.eq("display", "Y"));  

    AFTER FIX:
    criteria.add(Restrictions.eq("deleted", 'N'));
    criteria.add(Restrictions.eq("display", 'Y'));
  • There were issues with lazy loading getting org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: no session or session was closed ... Performance impact would have to be analyzed for each case.

No comments: