1

Trying to build simple spring integration app but it's failing for "emf" bean creation from following xml configuration file. I've tried java configuration mentioned in Spring JPA - org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean cannot be cast to javax.persistence.EntityManagerFactory but still getting the same error.

Using following spring versions:

spring 5.3.18, spring-integration 5.4.13,
hibernate 5.4.12.Final

XML Configuration:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/jee
        http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

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

    <bean id="emf"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="someDataSource" />
        <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
        <property name="persistenceUnitName" value="XXX" />
        <property name="persistenceUnitManager" ref="persistenceUnitManager" />
    </bean>

    <bean id="jpaVendorAdapter"
        class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    </bean>


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

    <bean id="persistenceUnitManager"
        class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
        <property name="defaultDataSource" ref="someDataSource" />
    </bean>

    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <constructor-arg ref="someDataSource"/>
    </bean>
    
    <jee:jndi-lookup id="someDataSource" jndi-name="Da:/someDS" />


</beans>
  • 1
    Please add the **full stacktrace** to your question, that will provide valuable info. I suspct you are deploying to some fullblown server (WebSphere, WildFly etc) which also has JPA embedded. Leading to classloading issues. – M. Deinum May 18 '22 at 14:18
  • Yes, I was deploying in Jboss server which already had JPA embedded. I had to exclude it. Adding link I referred : https://stackoverflow.com/questions/23663997/how-do-i-exclude-the-jboss-provided-javax-persistence-module. Thanks for help and apologies for super late reply. – Chinmay Raikwar Sep 15 '22 at 08:29

0 Answers0