Opened 12 years ago

Closed 10 years ago

#1742 closed task (fixed)

Upgrade to Hibernate 4.x

Reported by: Nicklas Nordborg Owned by: Nicklas Nordborg
Priority: critical Milestone: BASE 3.4
Component: core Version:
Keywords: Cc:

Description

Hibernate 4 has been around for quite some time now, but I have been reluctant to update, since I fear that it may affect/break a lot of things in BASE. Possible even things that are exposed as out public API.

It seems like the Hibernate developers are now working on Hibernate 5 (https://community.jboss.org/wiki/HibernateRoadmap) and that the 3.6.x branch is more or less abandoned. Sooner or later we have to update to a newer Hibernate, and it is usually better to do it sooner...

Change History (21)

comment:1 by Nicklas Nordborg, 10 years ago

Milestone: BASE Future ReleaseBASE 3.4
Owner: changed from everyone to Nicklas Nordborg
Status: newassigned

comment:2 by Nicklas Nordborg, 10 years ago

(In [6468]) References #1742: Upgrade to Hibernate 4.x

Updated to Hibernate 4.3.5.

  • Some 3rd-party libs has been updated/changed
  • PostgreSQLDialect has been deprecated and must be replaced with PostgreSQL9Dialect (affects base.config). Documentation need to be updated.
  • 2nd-level cache is configured differently. Hibernate will start, but I have not verified that it is actually used.
  • HibernateUtil.doJdbcWork() replaced with HibernateUtil.doWork() and HibernateUtil.doReturningWork() since Hibernate now has built-in support for return information from a work. Removed JdbcWork and lots of other changes needed because of this.
  • EntityMode parameter is no longer needed in lots of methods (I guess Hibernate has dropped support for other modes than POJO).
  • Quota.quotaValues changed from Map to Set since I could not get the map implemenation to work with Hibernate. The maxBytes property is now part of QuotaIndex.
  • Some internal Hibernate API has moved around to other packages.
  • unique-key annotations are now prefixed with the class name they appear in to avoid problems with accidentally duplicating another name (which fails in PostgreSQL since Hibernate has changed the naming strategy).

So far I have tested installation and TestAll on PostgreSQL. Need to test MySQL and updating also.

There are also some remaining calls to deprecated methods in Hibernate.

comment:3 by Nicklas Nordborg, 10 years ago

(In [6469]) References #1742: Upgrade to Hibernate 4.x

Replaced calls to deprecated methods in Hibernate:

  • Configuration.buildSessionFactory() new require a ServiceRegistry object
  • SQL with limit and offset parameters need to use a LimitHandler to set the parameters.

comment:4 by Nicklas Nordborg, 10 years ago

(In [6472]) References #1742: Upgrade to Hibernate 4.x

Forward call to wrapped query.

comment:5 by Nicklas Nordborg, 10 years ago

(In [6479]) References #1742: Upgrade to Hibernate 4.x

Documented change in PostgreSQL dialect.

comment:6 by Nicklas Nordborg, 10 years ago

(In [6521]) References #1742: Upgrade to Hibernate 4.x

Remove left-over code and fixed a forgotten wrapper method.

comment:7 by Nicklas Nordborg, 10 years ago

(In [6542]) References #1742: Upgrade to Hibernate 4.x

Trying to evict null values result in exception.

comment:8 by Nicklas Nordborg, 10 years ago

(In [6619]) References #1742: Upgrade to Hibernate 4.x

Fixed an issue with Hibernate throwing a ClassCastException when using setEntity on a query using StatelessSession. Hibernate tried to cast this to a Session object.

comment:9 by Nicklas Nordborg, 10 years ago

(In [6633]) References #1742: Upgrade to Hibernate 4.x

Replacing outer-join="auto" with nothing since Hibernate complained about outer-join being deprecated.

Also making some configuration options for ehcache that Hibernate wanted to use.

comment:10 by Nicklas Nordborg, 10 years ago

(In [6634]) References #1742: Upgrade to Hibernate 4.x

Resetting hibernate logging to off after debug.

comment:11 by Nicklas Nordborg, 10 years ago

Resolution: fixed
Status: assignedclosed

comment:12 by Nicklas Nordborg, 10 years ago

Resolution: fixed
Status: closedreopened

When updating a MySQL installation from 3.3 to 3.4 Hibernate generates several pairs of SQL statemtents for re-creating unique indexes:

alter table `Annotations` drop constraint Annotation_uniquetype
alter table `Annotations` add constraint Annotation_uniquetype  
  unique (`annotationset_id`, `annotationtype_id`)

The first statement fails because MySQL don't like the 'constraint' keyword:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 
  You have an error in your SQL syntax; check the manual that 
  corresponds to your MySQL server version for the right syntax 
  to use near 'constraint Annotation_uniquetype' at line 1

To fix the SQL, 'constraint' should be replaced with 'index', but then another problem arises, there is no index with the name Hibernate tries to drop so the SQL fails in any case.

Version 0, edited 10 years ago by Nicklas Nordborg (next)

comment:13 by Nicklas Nordborg, 10 years ago

As it turns out things seems to not be ok on PostgreSQL either. I have duplicate indexes with names:

  • Annotations_annotationset_id_annotationtype_id_key
  • annotation_uniquetype

But this is on an old database and I am not exactly sure how this has happened or why the "drop constraint" command didn't fail (due to a non-existing index) on PostgreSQL in the first place.

More testing is needed.

comment:14 by Nicklas Nordborg, 10 years ago

I checked updating a BASE 3.3 to 3.4 on PostgreSQL and it works. To begin with there is only one index (Annotations_annotationset_id_annotationtype_id_key). The updated creates the other index and the reason that the drop command doesn't fail is that it uses the 'if exists' syntax:

alter table "Annotations" drop constraint if exists Annotation_uniquetype

So the way forward would be something like:

  • For MySQL fix the drop command so that it works and actually drops the index if it exists.
  • Implement support for the SchemaUpdateScript.isQuiet() method (eg. ignore exceptions if TRUE).
  • Implement a feature that checks for duplicate indexes and remove all but one of them (keep the one with the shortest name). Can probably be done by the updateindexes.sh script.

comment:15 by Nicklas Nordborg, 10 years ago

(In [6667]) References #1742: Upgrade to Hibernate 4.x

Fixes the first two issues:

  • MySQLEngine now fixes the SQL commands to a syntax that is accepted by MySQL.
  • Failure to execute a script that is isQuiet()==true results in a log entry and not an error

comment:16 by Nicklas Nordborg, 10 years ago

(In [6668]) References #1742: Upgrade to Hibernate 4.x

Hopefully fixes the third issue. The updateindexes.sh should now detect duplicate indexes and remove all but one of them. It preferes to save the index with the same name as defined in Hibernate.

comment:17 by Nicklas Nordborg, 10 years ago

(In [6669]) References #1742: Upgrade to Hibernate 4.x

Fixes an issue with non-unique index names on PostgreSQL.

comment:18 by Nicklas Nordborg, 10 years ago

(In [6670]) References #1742: Upgrade to Hibernate 4.x

Updated documentation. The updateindexes.sh is now important for both MySQL and PostgreSQL.

comment:19 by Nicklas Nordborg, 10 years ago

(In [6672]) References #1742: Upgrade to Hibernate 4.x

XDoclet generation of Hibernate mapping files generated error messages for files not containing andy hibnernate mapping annotations and not specified in build.xml as something that should be parsed.

Solved by copying net/sf/based/core/data/* to a temporary directory before running XDoclet on only the files in the temporary directory.

comment:20 by Nicklas Nordborg, 10 years ago

(In [6673]) References #1742: Upgrade to Hibernate 4.x

Adding back check if Hibernate mapping files need to be created. It was removed for debug reasons and accidentally included in [6672].

comment:21 by Nicklas Nordborg, 10 years ago

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.