0

We are trying to upgrade to Java 8, meaning that we will need Spring 4, and to upgrade to spring 4 we need to migrate to Hibernate 4.3 (We are currently on 3.4).

During the upgrade, we concluded that there are some changes within the QueryImpl implementation (hibernate).

Within the setParameter(String name, Object value), there is a new typecheck added (via the bindValue method call that is done in the new hibernate implementation).

This is causing our repository implementation to break, because all our entities have a custom type as identifier. These custom types all extend a class named AbstractEntityId, containing the actual ID as a long.

The problem is that in all our queries, we pass the id as a long. Before the upgrade, this never was a problem. But due to the hibernate changes we now get an IllegalArgumentException because of the new typecheck that was added.

Is there a way to work around this problem, without needing to change our queries (and thus that we can keep passing long's). If not, what would be the most efficient solution to deal with this problem?

Sidenote: the check that was added in the new QueryImpl implementation of Hibernate:

if ( Collection.class.isInstance( bind ) && ! Collection.class.isAssignableFrom( parameterType ) ) {

Old implementation: hibernate-entitymanager-3.4.0.GA-jboss : org.hibernate.ejb.QueryImpl.class

New implementation: hibernate-entitymanager-4.3.11.Final : org.hibernate.jpa.internal.QueryImpl.class

Kaj
  • 2,445
  • 3
  • 23
  • 34
  • There is no need to upgrade hibernate to upgrade to Spring 4. Spring 4 supports hibernate 3, 4 and 5. Also you can still use Spring 3, just don't compile the code to java8 but use `target 1.7` and your code should still happily work with your old frameworks on JDK8. See http://stackoverflow.com/questions/24657418/spring-core-3-2-9-java-8 and https://spring.io/blog/2013/05/21/spring-framework-4-0-m1-3-2-3-available. Unless you want to use the JDK8 language features, then just keep the old hibernate version. – M. Deinum Jun 09 '16 at 10:47
  • @M.Deinum That's the problem, we want to able to compile to Java8 – Kaj Jun 09 '16 at 14:08
  • Then you should still be able to use hibernate3 you might need to do some custom types if you use the new time/data api in jdk8 but apart from that I would guess it should work. Spring doesn't have a requirement to upgrade as mentioned. – M. Deinum Jun 09 '16 at 14:10
  • @M.Deinum Okay, the spring migration guide says minimum of hibernate 3.6 is needed, we are on 3.4. But I'll reformat the question and drop the j8 stuff, we still want hibernate 4 (and even 5 later on) – Kaj Jun 09 '16 at 16:38

0 Answers0