#1979 closed enhancement (fixed)

Upgrade to Hibernate 5

Reported by: nicklas Owned by: nicklas
Priority: major Milestone: BASE 3.8
Component: core Version:
Keywords: Cc:

Description

Hibernate 5 was released about 6 months ago: http://in.relation.to/2015/08/20/hibernate-orm-500-final-release/

Hibernate 4.x and older are no longer maintained.

Change History (28)

comment:1 Changed 22 months ago by nicklas

(In [7053]) References #1979: Upgrade to Hibernate 5

Creating branch for working with this update since it will likely cause a lot of things to stop working initially.

comment:2 Changed 22 months ago by nicklas

(In [7054]) References #1979: Upgrade to Hibernate 5

Replaced Hibernate JAR and other files with those part of the Hibernate 5.0.7 release.

I currently get 51 errors and 35 warnings when trying to compile.

  • Most seem related to changes in how Hibernate is configured via the Configuration class.
  • As a consequence database schema generation also has several errors.
  • Transaction and session handling have lots of warnings.

comment:3 Changed 22 months ago by nicklas

(In [7055]) References #1979: Upgrade to Hibernate 5

Fixed compilation errors related to changes in Transaction and JdbcCoordinator.

Down to 43 errors and 35 warnings when trying to compile.

comment:4 Changed 22 months ago by nicklas

(In [7056]) References #1979: Upgrade to Hibernate 5

Updates related to changes in how LIMIT and OFFSET parameters are added to SQL statements.

Down to 39 errors and 35 warnings when compiling.

comment:5 Changed 22 months ago by nicklas

(In [7057]) References #1979: Upgrade to Hibernate 5

Updates related to custom property accessor implementation.

Down to 22 errors and 35 warnings when compiling.

comment:6 Changed 22 months ago by nicklas

(In [7058]) References #1979: Upgrade to Hibernate 5

Updates related to changes in Session interface.

Down to 18 errors and 5 warnings when compiling.

comment:7 Changed 22 months ago by nicklas

(In [7059]) References #1979: Upgrade to Hibernate 5

Updates related to changes for the sequence id generator.

Down to 18 errors and 2 warnings when compiling.

comment:8 Changed 22 months ago by nicklas

(In [7060]) References #1979: Upgrade to Hibernate 5

Started to fix problems related to changes in Hibernate configuration. Some code has been updated and some has simply been commented out for later fixing.

Down to 9 errors and 2 warnings when compiling.

comment:9 Changed 22 months ago by nicklas

(In [7061]) References #1979: Upgrade to Hibernate 5

Started to fix problems related to changes in database schema generation. Some code has been updated and some has simply been commented out for later fixing.

Down to 0 errors and 2 warnings when compiling.

Trying to start initdb results in an exception:

ERROR core:344 - Exception while loading mapping files
java.lang.UnsupportedOperationException: Cannot create XMLStreamReader or XMLEventReader from a javax.xml.transform.dom.DOMSource
        at com.sun.xml.internal.stream.XMLInputFactoryImpl.jaxpSourcetoXMLInputSource(Unknown Source)
        at com.sun.xml.internal.stream.XMLInputFactoryImpl.createXMLStreamReader(Unknown Source)
        at com.sun.xml.internal.stream.XMLInputFactoryImpl.createXMLEventReader(Unknown Source)
        at org.hibernate.boot.jaxb.internal.AbstractBinder.createReader(AbstractBinder.java:90)
        at org.hibernate.boot.jaxb.internal.AbstractBinder.bind(AbstractBinder.java:83)
        at org.hibernate.boot.jaxb.internal.JaxpSourceXmlSource.doBind(JaxpSourceXmlSource.java:29)
        at org.hibernate.boot.MetadataSources.addDocument(MetadataSources.java:409)
        at net.sf.basedb.core.HibernateUtil.addStaticMappings(HibernateUtil.java:339)
        at net.sf.basedb.core.HibernateUtil.init2(HibernateUtil.java:225)
        at net.sf.basedb.core.Application.start(Application.java:492)
        at net.sf.basedb.core.Install.createTables(Install.java:130)
        at net.sf.basedb.install.InitDB.main(InitDB.java:75)

comment:10 Changed 22 months ago by nicklas

(In [7062]) References #1979: Upgrade to Hibernate 5

Add configuration files with addInputStream(...) instead of addDocument(...) (after converting the XML Dom to a String). A new error:

org.hibernate.boot.InvalidMappingException: Could not parse mapping document: jar:file:/D:/Eclipse/Workspace/hibernate-5/www/WEB-INF/lib/base-core-3.8.0.jar!/net/sf/basedb/core/data/BioMaterialData.hbm.xml (INPUT_STREAM)
        at org.hibernate.boot.jaxb.internal.InputStreamXmlSource.doBind(InputStreamXmlSource.java:46)
        at org.hibernate.boot.jaxb.internal.InputStreamXmlSource.doBind(InputStreamXmlSource.java:38)
        at org.hibernate.boot.spi.XmlMappingBinderAccess.bind(XmlMappingBinderAccess.java:79)
        at org.hibernate.boot.MetadataSources.addInputStream(MetadataSources.java:369)
        at net.sf.basedb.core.HibernateUtil.addStaticMappings(HibernateUtil.java:343)
        at net.sf.basedb.core.HibernateUtil.init2(HibernateUtil.java:227)
        at net.sf.basedb.core.Application.start(Application.java:492)
        at net.sf.basedb.core.Install.createTables(Install.java:130)
        at net.sf.basedb.install.InitDB.main(InitDB.java:75)
Caused by: org.hibernate.boot.MappingException: Unable to perform unmarshalling at line number 80 and column 68. Message: cvc-complex-type.2.4.a: Invalid content was found starting with element 'filter'. One of '{"http://www.hibernate.org/xsd/orm/hbm":property, "http://www.hibernate.org/xsd/orm/hbm":many-to-one, "http://www.hibernate.org/xsd/orm/hbm":one-to-one, "http://www.hibernate.org/xsd/orm/hbm":component, "http://www.hibernate.org/xsd/orm/hbm":dynamic-component, "http://www.hibernate.org/xsd/orm/hbm":properties, "http://www.hibernate.org/xsd/orm/hbm":any, "http://www.hibernate.org/xsd/orm/hbm":map, "http://www.hibernate.org/xsd/orm/hbm":set, "http://www.hibernate.org/xsd/orm/hbm":list, "http://www.hibernate.org/xsd/orm/hbm":bag, "http://www.hibernate.org/xsd/orm/hbm":array, "http://www.hibernate.org/xsd/orm/hbm":primitive-array, "http://www.hibernate.org/xsd/orm/hbm":idbag, "http://www.hibernate.org/xsd/orm/hbm":join, "http://www.hibernate.org/xsd/orm/hbm":subclass, "http://www.hibernate.org/xsd/orm/hbm":loader, "http://www.hibernate.org/xsd/orm/hbm":sql-insert, "http://www.hibernate.org/xsd/orm/hbm":sql-update, "http://www.hibernate.org/xsd/orm/hbm":sql-delete, "http://www.hibernate.org/xsd/orm/hbm":fetch-profile, "http://www.hibernate.org/xsd/orm/hbm":resultset, "http://www.hibernate.org/xsd/orm/hbm":query, "http://www.hibernate.org/xsd/orm/hbm":sql-query}' is expected. : origin(jar:file:/D:/Eclipse/Workspace/hibernate-5/www/WEB-INF/lib/base-core-3.8.0.jar!/net/sf/basedb/core/data/BioMaterialData.hbm.xml)
        at org.hibernate.boot.jaxb.internal.AbstractBinder.jaxb(AbstractBinder.java:177)
        at org.hibernate.boot.jaxb.internal.MappingBinder.doBind(MappingBinder.java:61)
        at org.hibernate.boot.jaxb.internal.AbstractBinder.doBind(AbstractBinder.java:102)
        at org.hibernate.boot.jaxb.internal.AbstractBinder.bind(AbstractBinder.java:57)
        at org.hibernate.boot.jaxb.internal.InputStreamXmlSource.doBind(InputStreamXmlSource.java:43)
        ... 8 more

comment:11 Changed 22 months ago by nicklas

(In [7063]) References #1979: Upgrade to Hibernate 5

Temporarily disable adding <filter> tag to <subclass> elements.

Database schema generation is working now and initdb.bat runs without errors. The database that is generated is more or less the same. The following differences have been found (PostgreSQL/MySQL):

  • Different column order in some create table... statements (not critical)
  • Some sql statements are generated in different order (not critical)
  • Different names for unique/foreign keys (not critical and expected since names are randomly generated)
  • Missing sequences for raw data tables (PostgreSQL only; needs to be fixed)

comment:12 Changed 22 months ago by nicklas

(In [7064]) References #1979: Upgrade to Hibernate 5

Configuration parameter for database sequence has changed from sequence to sequence_name. This is what caused the missing seqeunces for raw data table mentioned in [7063] since all sequences used the default name (hibernate_sequence).

comment:13 Changed 22 months ago by nicklas

(In [7065]) References #1979: Upgrade to Hibernate 5

Add a copy of /org/hibernate/hibernate-mapping-4.0.xsd. The one included in Hibernate JAR seems to have a bug that prevents us from validating <many-to-any> tags.

comment:14 Changed 22 months ago by nicklas

(In [7066]) References #1979: Upgrade to Hibernate 5

Added minoccurs="2" to <column> inside <many-to-any> since at least two columns are required.

comment:15 Changed 22 months ago by nicklas

(In [7067]) References #1979: Upgrade to Hibernate 5

Validating mapping files with the XSD schema instead of DTD. To make similar changes easier in the future we leave the <hibernate-mapping> element without any schema declaration and let ant make a search-and-replace in build.xml.

comment:16 Changed 22 months ago by nicklas

(In [7068]) References #1979: Upgrade to Hibernate 5

TestProject failed when trying to set a default item. Seems like Hibernate is trying to insert a 'null' value instead of the data class name. Setting an empty meta-type value for the mapping seems to fix the problem. Below is the stacktrace:

--Set default item FAILED (Protocol; id=1069)
net.sf.basedb.core.DatabaseException: ERROR: null value in column "data_class" violates not-null constraint
  Detail: Failing row contains (1075, null, 1069).
        at net.sf.basedb.core.HibernateUtil.commit(HibernateUtil.java:1352)
        at net.sf.basedb.core.DbControl.commit(DbControl.java:515)
        at TestProject.test_defaultItem(TestProject.java:117)
        at TestProject.test_all(TestProject.java:79)
        at TestProject.main(TestProject.java:39)
Caused by: org.postgresql.util.PSQLException: ERROR: null value in column "data_class" violates not-null constraint
  Detail: Failing row contains (1075, null, 1069).
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1998)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:420)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:366)
        at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:461)

        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:204)
        at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)
        at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1313)
        at org.hibernate.action.internal.CollectionRecreateAction.execute(CollectionRecreateAction.java:50)
        at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:560)
        at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:434)
        at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
        at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
        at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1282)
        at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:465)
        at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2963)
        at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2339)
        at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:485)
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:147)
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:231)
        at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:65)
        at net.sf.basedb.core.HibernateUtil.commit(HibernateUtil.java:1347)
        ... 4 more

comment:17 Changed 22 months ago by nicklas

(In [7069]) References #1979: Upgrade to Hibernate 5

Fixing code for defining dynamic tables. All test programs now work and there are no compilation error or warnings. There is still some code that has been commented out.

comment:18 Changed 22 months ago by nicklas

(In [7070]) References #1979: Upgrade to Hibernate 5

Fixing issues with <filter> definitions. The previous strategy that added <filter> tags dynamically to the hbm.xml files doesn't work since <filter> inside <subclass> doesn't validate against the schema. Instead we need to collect the filters that we want to define and then wait until the configuration process has come far enough so that we have access to a Metadata instance and PersistentCollection objects. This is similar to how filters was registered before the changes in [5477] #1547.

comment:19 Changed 22 months ago by nicklas

(In [7071]) References #1979: Upgrade to Hibernate 5

Seems like Hibernate schema update tool once again has problems with generating duplicates (see [6668]). This time it is foreign key definitions that are generated and created with new names. I think it is better to let Hibernate only generate the tables and instead implement the index and foreign key creation into or own code. Most of what is needed is already present in DbIndexWork and related classes. It just needs to be packaged a bit differently. If we do this then there is also no need to manually run updateindexes.sh as part of the installation.

In this changeset I have made changes so that all "create index" and "alter table...drop|add constraint" SQL statemnts are ignored.

comment:20 Changed 22 months ago by nicklas

(In [7072]) References #1979: Upgrade to Hibernate 5

Major changes to the database schema creation/update procedure. Basically we only trust Hibernate to create the tables and add columns to existing tables. Foreign keys and indexes are now created and managed with the DbIndexWork class instead. This has now been integrated into the main installation and there should be no need to run updateindexes.sh after an installation. The documentation need to be updated.

comment:21 Changed 22 months ago by nicklas

(In [7073]) References #1979: Upgrade to Hibernate 5

Remove debug output

comment:22 Changed 21 months ago by nicklas

(In [7074]) References #1979: Upgrade to Hibernate 5

New API for building session factories via ServiceSessionControl. This is a change that breaks binary backwards compatibility for extensions that use the BASE database for storing extra data.

comment:23 Changed 21 months ago by nicklas

(In [7075]) References #1979: Upgrade to Hibernate 5

Reintegrates changes made in /hibernate5 branch to the trunk

comment:24 Changed 21 months ago by nicklas

(In [7076]) References #1979: Upgrade to Hibernate 5

Remove /hibernate-5 branch since it has been integrated to the trunk.

comment:25 Changed 21 months ago by nicklas

(In [7079]) References #1979: Upgrade to Hibernate 5

Updated documentation:

  • Added information about that updateindexes.sh is no longer needed.
  • Incompatible API in ServiceSessionControl

comment:26 Changed 19 months ago by nicklas

  • Owner changed from everyone to nicklas
  • Status changed from new to assigned

comment:27 Changed 19 months ago by nicklas

(In [7144]) References #1979: Upgrade to Hibernate 5

'null' and an empty set is no longer considered equal by Hibernate. We need to return the same instance as given to us by Hibernate or Hibernate will generate an UPDATE query for the item. Since nothing has actually changed the update only increases the 'version' property which may lead to StaleStateException (Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1)

comment:28 Changed 19 months ago by nicklas

  • Resolution set to fixed
  • Status changed from assigned to closed

All tests have now been completed successfully.

Note: See TracTickets for help on using tickets.