Opened 8 years ago

Closed 7 years ago

#2084 closed enhancement (fixed)

Upgrade to Hibernate 5.2

Reported by: Nicklas Nordborg Owned by: Nicklas Nordborg
Priority: major Milestone: BASE 3.12
Component: core Version:
Keywords: Cc:

Description

Latest version is Hibernate 5.2.10 (we are currently running Hibernate 5.0.7).

As always, it is a bit complicated to update Hibernate. Simply replacing the old JAR file with the new version causes 131 errors and 1477 warnings. Most seems to be related to things that have been moved around due to merging the Hibernate API with the Java Persistence API (JPA) (see https://github.com/hibernate/hibernate-orm/wiki/Migration-Guide---5.2).

Hopefully, this change will not be as difficult as the last Hibernate update (#1979).

Change History (31)

comment:1 by Nicklas Nordborg, 8 years ago

Owner: changed from everyone to Nicklas Nordborg
Status: newassigned

comment:2 by Nicklas Nordborg, 8 years ago

Summary: Upgrade HibernateUpgrade to Hibernate 5.2

comment:3 by Nicklas Nordborg, 8 years ago

(In [7362]) References #2084: Upgrade to Hibernate 5.2

Replaced old JAR files with new versions. Causes 131 compile errors and 1477 warnings.

comment:4 by Nicklas Nordborg, 8 years ago

(In [7363]) References #2084: Upgrade to Hibernate 5.2

Updated QueryWrapper and EntityQueryWrapper to use the new org.hibernate.query.Query interface. Down to 95 errors and 1398 warnings.

comment:5 by Nicklas Nordborg, 8 years ago

(In [7364]) References #2084: Upgrade to Hibernate 5.2

Updated SessionWrapper and StatelessSessionWrapper with new API methods. 26 error and 1328 warnings remaining.

comment:6 by Nicklas Nordborg, 8 years ago

(In [7365]) References #2084: Upgrade to Hibernate 5.2

Updated ExtendedPropertyAccessor. 24 errors and 1328 warnings remaining.

comment:7 by Nicklas Nordborg, 8 years ago

(In [7366]) References #2084: Upgrade to Hibernate 5.2

Temporary fix in HibernateUtil. Need to replace all org.hibernate.Query with org.hibernate.query.Query but that causes a lot of additional compilation errors. 22 errors and 1332 warnings remaining.

comment:8 by Nicklas Nordborg, 8 years ago

(In [7367]) References #2084: Upgrade to Hibernate 5.2

Fixed compilation errors in DbIndexWork and SchemaGenerator. The code can now be compiled (1332 warnings) and the installation program runs without any problem.

Need to compare the generated database with one generated with the old Hibernate.

Some test program fails:

TestUser FAILED                       
TestGlobalDefaultSetting FAILED       
TestClientDefaultSetting FAILED       
TestUserDefaultSetting FAILED         
TestUserClientSetting FAILED          
TestReporter FAILED                   
TestReporterList FAILED               
TestArrayDesign FAILED                
TestRawBioAssay FAILED                
TestSpotImages FAILED                 
TestDbControl FAILED                  
TestReporterFlatFileImporter FAILED   
TestReporterMapFlatFileImporter FAILED
TestPlateFlatFileImporter FAILED      
TestRawDataFlatFileImporter FAILED    
TestPrintMapFlatFileImporter FAILED   
TestGalExporter FAILED                
TestDirty FAILED                      
TestIlluminaImporter FAILED           
TestGtfImporters FAILED               
TestBasicAnalysis FAILED              
TestReporterCloneTemplate FAILED      
TestIntensityCalculatorPlugin FAILED  
TestLowessNormalization FAILED        
TestMedianRatioNormalization FAILED   
TestBaseFileExporterImporter FAILED   
TestBfsExporterImporter FAILED        
TestBase1PluginExecuter FAILED        
TestExternalProgramExecutor FAILED    
++29 tests failed!                    
++78 tests succeeded!                 

comment:9 by Nicklas Nordborg, 8 years ago

I have now compared the databases generated with Hibernate 5.0 and Hibernate 5.2. They are identical!

comment:10 by Nicklas Nordborg, 8 years ago

(In [7368]) References #2084: Upgrade to Hibernate 5.2

Hibernate is throwing different exception now which caused some of our error handling code to failed (eg. detecting duplicates in the database). Trying to get back as much of the old behaviour as possible. This fixes a few failed tests:

TestReporter FAILED
TestReporterList FAILED
TestArrayDesign FAILED
TestRawBioAssay FAILED
TestSpotImages FAILED
TestDbControl FAILED
TestItemImporter FAILED
TestReporterFlatFileImporter FAILED
TestReporterMapFlatFileImporter FAILED
TestPlateFlatFileImporter FAILED
TestRawDataFlatFileImporter FAILED
TestPrintMapFlatFileImporter FAILED
TestGalExporter FAILED
TestDirty FAILED
TestIlluminaImporter FAILED
TestGtfImporters FAILED
TestBasicAnalysis FAILED
TestReporterCloneTemplate FAILED
TestIntensityCalculatorPlugin FAILED
TestLowessNormalization FAILED
TestMedianRatioNormalization FAILED
TestBaseFileExporterImporter FAILED
TestBfsExporterImporter FAILED
TestBase1PluginExecuter FAILED
TestExternalProgramExecutor FAILED
++25 tests failed!
++82 tests succeeded!

comment:11 by Nicklas Nordborg, 8 years ago

(In [7369]) References #2084: Upgrade to Hibernate 5.2

Hibernate has changed the ID generation implementation. This caused or batchers to create incorrect SQL for PostgreSQL (not tested with MySQL yet). This fixes most of the remaining tests:

TestDbControl FAILED
++1 tests failed!
++106 tests succeeded!

comment:12 by Nicklas Nordborg, 8 years ago

The failure in the DbControl test is in the DbControl.disconnect() method. It turns out we are using a Hibernate API in a way that it was not intended to be used. From the Hibernate API:

It is considered an error to call this method on a session which 
was not opened by supplying the JDBC connection and an exception 
will be thrown. 

Ok, we are not getting any exception but it seems that we are now losing changes made to items during the time the DbControl was not connected. As far as I can tell, we only use this feature in the file upload (there is no need to keep the database connection open during the file upload).

I think we should deprecate the DbControl.disconnect() and DbControl.reconnect() methods since there is no way to implement what we want in a generic way. The implementation should be changed to simply not doing anything at all.

Client code that need to disconnect/reconnect should be updated to handle this by using two separate DbControl instances.

comment:13 by Nicklas Nordborg, 8 years ago

(In [7370]) References #2084: Upgrade to Hibernate 5.2

The disconnect()/reconnect() methods are now no-op and deprecated. Removed the test case. All tests are now working. Remains to fix the file upload code.

comment:14 by Nicklas Nordborg, 8 years ago

(In [7371]) References #2084: Upgrade to Hibernate 5.2

Started to replace org.hibernate.Query with org.hibernate.query.Query in the remaining code. Compilation errors up again to 306 and warnings to 1198.

comment:15 by Nicklas Nordborg, 8 years ago

(In [7372]) References #2084: Upgrade to Hibernate 5.2

A global search/replace of org.hibernate.Query with org.hibernate.query.Query. Down to 140 compilation errors but warnings up to 1311 (probably because we are missing a type-parameter for the Query).

comment:16 by Nicklas Nordborg, 8 years ago

(In [7373]) References #2084: Upgrade to Hibernate 5.2

Fixed compilation errors related to not using return type parameter on org.hibernate.query.Query. All compilation errors gone, but 1163 warnings remaining.

comment:17 by Nicklas Nordborg, 8 years ago

(In [7374]) References #2084: Upgrade to Hibernate 5.2

Replaced calls to Query.setInteger() and other type-specific methods to Query.setParameter() and specified return-type parameter for many queries. Number of warnings down to 556.

comment:18 by Nicklas Nordborg, 8 years ago

(In [7375]) References #2084: Upgrade to Hibernate 5.2

Using createNativeQuery() with a return type that is not a defined entity (for example Integer) caused Hibernate to complain. The variant without a return type seems to work though...

comment:19 by Nicklas Nordborg, 8 years ago

(In [7376]) References #2084: Upgrade to Hibernate 5.2

Replaced calls to Query.setEntity() with Query.setParameter() and specified return-type parameter for many queries. Number of warnings down to 185.

comment:20 by Nicklas Nordborg, 8 years ago

(In [7377]) References #2084: Upgrade to Hibernate 5.2

Fixed all remaining queries without a return type parameter. Number of warnings down to 13.

Last edited 8 years ago by Nicklas Nordborg (previous) (diff)

comment:21 by Nicklas Nordborg, 8 years ago

(In [7378]) References #2084: Upgrade to Hibernate 5.2

Getting rid of some more calls to deprecated method. Most have simple replacements, but the various NativeQuery.addXXXX() are a bit more complicated. Lycklily we can either replace them with a Object[] return type or by re-adding the possibility to speify a return type (as long as it matches a defined entity). See [7375]. A new test case in TestReporterCloneTemplate was added to check that this works.

comment:22 by Nicklas Nordborg, 8 years ago

(In [7379]) References #2084: Upgrade to Hibernate 5.2

Cleaning out some more query-related stuff.

comment:23 by Nicklas Nordborg, 8 years ago

(In [7380]) References #2084: Upgrade to Hibernate 5.2

comment:24 by Nicklas Nordborg, 8 years ago

(In [7381]) References #2084: Upgrade to Hibernate 5.2

Merged development branch back to trunk since it seems to be working now.

comment:25 by Nicklas Nordborg, 8 years ago

Resolution: fixed
Status: assignedclosed

comment:26 by Nicklas Nordborg, 8 years ago

Resolution: fixed
Status: closedreopened

Database schema update is not working when adding a column to an existing table. The generated SQL statement has no quotes around the table which is causing an exception.

org.postgresql.util.PSQLException: ERROR: relation "public.news" does not exist
	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412)
	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297)
	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301)
	at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287)
	at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264)
	at org.postgresql.jdbc.PgStatement.executeUpdate(PgStatement.java:244)
	at com.mchange.v2.c3p0.impl.NewProxyStatement.executeUpdate(NewProxyStatement.java:410)
	at net.sf.basedb.core.hibernate.SchemaGenerator.execute(SchemaGenerator.java:173)
	at org.hibernate.jdbc.WorkExecutor.executeWork(WorkExecutor.java:37)
	at org.hibernate.internal.SessionImpl$1.accept(SessionImpl.java:2321)
	at org.hibernate.internal.SessionImpl$1.accept(SessionImpl.java:2318)
	at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.coordinateWork(JdbcCoordinatorImpl.java:314)
	at org.hibernate.internal.SessionImpl.doWork(SessionImpl.java:2340)
	at org.hibernate.internal.SessionImpl.doWork(SessionImpl.java:2325)
	at net.sf.basedb.core.HibernateUtil.createStaticTables(HibernateUtil.java:769)
	at net.sf.basedb.core.Install.createTables(Install.java:139)
	at net.sf.basedb.install.InitDB.main(InitDB.java:75)

comment:27 by Nicklas Nordborg, 8 years ago

(In [7391]) References #2084: Upgrade to Hibernate 5.2

Implemented a workaround for the unquoted table name problem. It is a bit of a "hack" that involves replacing a private and final variable inside a Hibernate class with our own implementation that forces names to be quoted. We do this only when doing a database schema update and revert to the original value afterwards.

comment:28 by Nicklas Nordborg, 8 years ago

(In [7396]) References #2084: Upgrade to Hibernate 5.2

Need to begin a transaction when creating a new piggy-backed session or Hibernate will complain about no active transaction when trying to commit.

comment:29 by Nicklas Nordborg, 7 years ago

Resolution: fixed
Status: reopenedclosed

comment:30 by Nicklas Nordborg, 7 years ago

Resolution: fixed
Status: closedreopened

Schema update still does not work with !MySQL. I am getting:

ERROR SchemaGenerator:252 - Schema update failed while executing: 
  create table `AnnotationSets` (`id` integer not null auto_increment,
  `version` integer not null, `item_type` integer not null, `item_id`
  integer, primary key (`id`)) engine=InnoDB
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 
  Table 'annotationsets' already exists

With logging enabled I also get:

INFO InformationExtractorJdbcDatabaseMetaDataImpl:508 - 
  HHH000262: Table not found: `AnnotationSets`
// ... and a lot more for each of the already existing tables

I think it is a problem with upper- vs. lower-casing of table names which Hibernate is not handling correctly.

comment:31 by Nicklas Nordborg, 7 years ago

Resolution: fixed
Status: reopenedclosed

Seems to be working now after testing with both PostgreSQL and MySQL.

Note: See TracTickets for help on using tickets.