0

I'm failling to use Spring4 togather with Hibernate4 in a standalone process (no container like tomcat, WAS, ...)

How can I use Hibernate4, Spring4 and Spring data repositories togather in a standalone process?

However I confiugre Spring I allways get the same exception:

Caused by: java.lang.NullPointerException
at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:76)
at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.isActive(JtaStatusHelper.java:118)
at org.hibernate.engine.transaction.internal.jta.CMTTransaction.join(CMTTransaction.java:149)

When googling for this, I get pointet to some information about hibernate.transaction.jta.platform and the docu for Hibernate 4.3 is here http://docs.jboss.org/hibernate/orm/4.3/devguide/en-US/html_single/#services-JtaPlatform

But the only option I see for my case would be org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform but this still leads to the same error.

Here is my Spring config:

    <context:component-scan base-package="com.xx.yy" />
<jpa:repositories base-package="com.xx.zz.respositories"></jpa:repositories>

<bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/culture" />
    <property name="username" value="root" />
    <property name="password" value="" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
    <property name="jpaDialect">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
    </property>
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="jtaDataSource" ref="dataSource" />
    <property name="packagesToScan" value="culture.matching.index.model" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="generateDdl" value="true" />
            <property name="showSql" value="false" />
            <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
            <property name="database" value="MYSQL" />
        </bean>
    </property>
    <property name="jpaProperties">
        <value>
            hibernate.transaction.jta.platform=org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform
        </value>
    </property>
</bean>
domi
  • 2,167
  • 1
  • 28
  • 45
  • 1
    Need to remove all the references to JTA - you have no JTA container. Also, why are you still using XML if you are using Spring 4? – Boris the Spider Mar 22 '14 at 15:34
  • Which references do you mean? The only reference to JTA I see in the config is 'jtaDataSource' and even if I change this to 'dataSource' the same problem exists. – domi Mar 22 '14 at 15:37
  • [Found a decent tutorial](http://geowarin.github.io/2013/01/21/using-spring-data-jpa-in-a-java-se-environment-and-run-tests-with-dbunit/) that should get you up and running. – Boris the Spider Mar 22 '14 at 15:45
  • I would urge you to take a look at Spring Boot which can vastly reduce the amount of configuration you need to write for Spring applications (whether they are web or standalone application). Take a look at this link https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-simple – geoand Mar 22 '14 at 15:50
  • @BoristheSpider strange enough, the tutorial you'r pointing to also uses the 'LocalContainerEntityManagerFactoryBean' – domi Mar 22 '14 at 15:54
  • @domi yeah, I noticed that. – Boris the Spider Mar 22 '14 at 15:55
  • Another great resource for checking out how Spring Boot will help you remove most (almost all that this) Spring configururation, check out this guide http://spring.io/guides/gs/accessing-data-jpa/ – geoand Mar 22 '14 at 16:03
  • @BoristheSpider but I got it wokring with the javaconfig of the tutorial you pointed me to - many thanks!!! – domi Mar 22 '14 at 16:18
  • @geoand thanks for the hint to spring-boot - I might actually do that, but It will require quite some refactoring – domi Mar 22 '14 at 16:19
  • @domi If you are still in this initial stages of development and can manage the cost of some refactoring, it is probably worth it to check out boot! – geoand Mar 22 '14 at 16:24

1 Answers1

0

Answer by @geoand helped a lot: https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-simple I therefore moved from XML to Java config

domi
  • 2,167
  • 1
  • 28
  • 45
  • Hi, your reference is dead. Please follow the rules - you always must directly include the important citations. Only prooves and alternatives are what you can leave out of the answer. – Gangnus Nov 15 '20 at 18:58