We want to migrate from hibernate 3 to hibernate 4. The main reason being the envers integration.
Part of our application performs jdbc calls via iBatis (via an external bpm product: activiti),
the other part access the database via jpa.
Everything worked fine with hibernate 3.
I guess we have to change something in the configuration in order to make it work.
This the pertinent part of the config
and the foo-persistence.xmlCode:<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="jpaVendorAdapter"> <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="database" value="db2"/> <property name="databasePlatform" value="ch.foo.dialect.DB2zOSDialect"/> </bean> </property> <property name="jpaProperties"> <props> <prop key="hibernate.dialect">ch.foo.dialect.DB2zOSDialect</prop> <prop key="hibernate.hbm2ddl.auto">false</prop> </props> </property> <property name="persistenceXmlLocation" value="classpath:META-INF/foo-persistence.xml"/> </bean> <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:comp/env/jdbc/foo"/> <property name="resourceRef" value="true"/> </bean> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory"/> </bean>
What I could observeCode:<persistence-unit name="foo" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <mapping-file>META-INF/foo-orm.xml</mapping-file> </persistence-unit>
Activiti checks the database by calling these 2 methods one after the other:
The getTables returns null, hiding a NullPointerException thrown in org.hibernate.engine.jdbc.internal.proxy.Connectio nProxyHandler#getResourceRegistry.Code:In Class org.activiti.engine.impl.db.DbSqlSession DatabaseMetaData databaseMetaData = connection.getMetaData(); // line 689 tables = databaseMetaData.getTables(..) // line 708
The connection.getMetaData() goes through org.springframework.jdbc.datasource.TransactionAwa reDataSourceProxy.TransactionAwareInvocationHandle r#invoke
where a connection is retrieved and released.
The connection (logicalConnection) is hold in the org.hibernate.engine.jdbc.internal.proxy.Connectio nProxyHandler.
The getTables will try to retrieve the connection from the ConnectionProxyHandler, which will fail with a NullPointerException.
Workaround
I could workaround the problem by patching org.hibernate.engine.jdbc.internal.proxy.Connectio nProxyHandler#continueInvocation.
The result of method (getMetaData()) is wrapped in the ConnectionProxyHandler. By removing the wrapping I got back the expected behavior (Well I'm not sure of that as I don't know why it was wrapped in the first place)
I can't live for long with a patched Hibernate version.Code:Object result = method.invoke(extractPhysicalConnection(), args); // result = postProcess(result, proxy, method, args); <-- patch, commented : line 139
My guess is that I have to change something in the config.
I tried a few things, but I don't have any more ideas![]()
The question
The final question how can I configure hibernate 4 so that my use case works?
Thanks
Spring version: 3.1.1
Hibernate version: 4.1.4
Tomcat 7.0.23


Reply With Quote
