Hibernate Upgrade Analysis (October 2007)

The following page gives an overview of the conclusions collected by the analysis work done in October 2007 for the Hibernate upgrade.

Task Description

As of April 2007, mifos is using Hibernate 3.0beta4 (checked in to the mifos lib directory). At this point we are looking to upgrade to version 3.2.5ga.

Upgrade Instructions

To get to a starting point, update the hibernate jar in the lib directory to the most recent (as of October 2007, this is 3.2.5ga) then apply this patch.

Summary:

  • Improvements in hibernate offer more restrictive assertions in it's usage. These assertions are exposing significant design flaws in the code that will need to be addressed before we can upgrade.
  • The most widespread issue is the misuse of Sessions and Transactions. This later version of Hibernate becomes a lot more strict about opening and closing Sessions and Transactions. See the following issues for details: _ Transaction Not Successfully Started _ Session was already closed * Trying to use a closed Session
  • The biggest issue in my opinion is related to Mayfly (see this issue for details). Problems with Mayfly are difficult to estimate and they're further complicated due to the fact that the Mayfly project has not been active for some time (their's no support).
  • ~10% of the issues that I ran into appeared to be indirectly related to the other recorded issues. Further analysis would be required to be sure.
  • I believe that I am aware of at least 75% of the scope of this upgrade task as a result of this analysis.

Recommendation:

  • I would suggest upgrading Hibernate (updating the jar) at the beginning of the next release.
  • Deal with the issues that were exposed. Determine which issues should be dealt with before the 1.1 release.

Questions:

What are the impacts of not doing this upgrade before the 1.1 release?:

  • Question: What is the potential impact on database upgrades of not doing the hibernate upgrade right away--hopefully there is no impact so we can safely defer without incurring additional upgrade work related to this.
  • Response: There isn't anything specifically related to the Hibernate upgrade that has a significant impact. This is a 'point' release (i.e. 3.0b4 to 3.2.5ga) so there should not be any significant schema or api changes.
    HOWEVER, the upgrade did expose problems deleting objects in the test cases (see this issue). This is part of a larger, DataIntegrity issue.

Analysis Details (October 3rd, 2007)

Steps Taken

  • Updated to hibernate 3.2.5ga (updated the jar)
  • Fixed some minor build/compile issues (see above patch for details)
  • Executed the 'run_test_parallel_4' ant task and analyzed results of failures.

Issues From Analysis:

Problems deleting some objects

TestCustomerPersistence (as is) fails because setUp() tries to delete persisted client object, but violates several foreign key contraints, in beta version hibernate did not check this for session items (it left it to the database). This points at a larger problem, that some objects are not deletable, though they probably should be - for example, performanceHistory. No change was made with regard to the relations between these objects, rather the approach is to migrate the tests to use mayfly (in memory database) TestDatabase and call TestDatabase#resetDatabase in tearDown.

Further discussion here: DataIntegrity

Session.connection() has been deprecated

this is causing compile to fail because the ant task is currently set to fail on deprecations.

Chosen Option:

Remove the deprecation option from the ant build - this is the quick-fix, but not the best option. it's important that we use compile errors to reject deprecated code out of our build. allowing deprecated code is one of those slippery slopes that ends in very confusing code.

Recommended Option:

Discussion here: SessionConnectionDeprecation

org.hibernate.TransactionException: Transaction not successfully started

Discussed here: TransactionManagementIssues

Example Test Case:

  • Output file: ApplicationTestSet1
  • Test Case: org.mifos.application.productsmix.business.ProductMixBOTest.testUpdate()

This feature is not yet implemented in Mayfly

Discussed here: InMemoryDatabase

Example Test Case:

  • Output file: ApplicationTestSet1
  • Test Case: org.mifos.framework.security.AddActivityTest.startFromStandardStore()

Session was already closed

Discussed here: Session Management Issues

Example Test Case:

  • Output file: ApplicationTestSet1
  • Test Case: org.mifos.application.accounts.savings.business.service.TestSavingsBusinessService.testRetrieveCustomFieldsDefinitionForInvalidConnection()

Trying to use a closed session

Discussed here: Session Management Issues

Example Test Case:

  • Output file: ApplicationTestSet1
  • Test Case: org.mifos.application.accounts.savings.business.service.TestSavingsBusinessService.testFindByIdForInvalidConnection()

NumberFormatException when trying to parse id's

Example Test Case:

  • Output file: ApplicationTestSet3
  • Test Case: org.mifos.application.office.struts.action.TestOfficeAction.testCreate()

org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter

Example Test Case:

  • Output file: ApplicationTestSet3
  • Test Case: org.mifos.application.customer.center.struts.action.CenterActionTest.testSearch()