4 Replies Latest reply on May 4, 2014 4:37 AM by malpi

    Howto JBoss AS7 and Spring Data JPA


      Hi there,


      i am trying to get an application running which is using JBoss as application server. Furthermore I want to use Spring Data JPA without the Spring Application Context, so lets say plain JEE.


      Spring provides a CDI extension which should natively work. But I am always getting the following exception.


      javax.enterprise.inject.UnsatisfiedResolutionException: Unable to resolve a bean for 'javax.persistence.EntityManager' with qualifiers [@javax.enterprise.inject.Any(), @javax.enterprise.inject.Default()].

          at org.springframework.data.jpa.repository.cdi.JpaRepositoryExtension.createRepositoryBean(JpaRepositoryExtension.java:112)

          at org.springframework.data.jpa.repository.cdi.JpaRepositoryExtension.afterBeanDiscovery(JpaRepositoryExtension.java:91)

      I followed the spring reference guide, which state to create an Entitymanger producer. (http://docs.spring.io/spring-data/jpa/docs/1.4.2.RELEASE/reference/html/jpa.repositories.html#jpd.misc.cdi-integration)


          public EntityManagerFactory createEntityManagerFactory() {
              return Persistence.createEntityManagerFactory("persistenceUnit");
          public void close(@Disposes EntityManagerFactory entityManagerFactory) {


      But still the exception stays..

      My persistence.xml looks like the following:


      <?xml version="1.0" encoding="UTF-8" standalone="no"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
          <persistence-unit name="persistenceUnit" transaction-type="JTA">
                  <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
                  <!-- value="create" to build a new database on each run; value="update" 
                      to modify an existing database; value="create-drop" means the same as "create" 
                      but also drops tables when Hibernate closes; value="validate" makes no changes 
                      to the database -->
                  <property name="hibernate.hbm2ddl.auto" value="create" />
                  <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" />
                  <property name="hibernate.connection.charSet" value="UTF-8" />
                  <property name="hibernate.default_schema" value="public" />
                  <property name="hibernate.show_sql" value="false" />
                  <property name="jboss.entity.manager.factory.jndi.name" value="java:/ttsEntityManagerFactory"/> 


      I only put line 22 in there because it was stated in the JBOSS documentation, but it didn't change anything.

      Somebody has an idea how to solve the exception? Or knows an example?


      Thanks in advance,



        • 1. Re: Howto JBoss AS7 and Spring Data JPA

          The only way I found is to declare entity manager factory and entity manager itself in the following way:


          public class CdiConfig {
              private EntityManagerFactory entityManagerFactory;
              public EntityManager createEntityManager(EntityManagerFactory emf) {
                  return emf.createEntityManager();
              public void close(@Disposes EntityManager entityManager) {


          I'm not sure of behavior of this @Dependent scope and how it will behave: memory leaks, performance etc. However, I was able to run and use Spring Data Jpa repositories with this configuration and Jboss EAP 6.2.

          • 2. Re: Howto JBoss AS7 and Spring Data JPA

            thanks, your CdiConfig save me a day.


            this could run well with Arquillian test, jboss 6.2

            • 3. Re: Howto JBoss AS7 and Spring Data JPA

              I found another configuration that works better and correct:

              public class CdiConfig {
                  private EntityManager entityManager;
              • 4. Re: Howto JBoss AS7 and Spring Data JPA

                Hi there,


                In the meantime I already found a solution and I concluded them in a blogpost.




                Best Regards,



                1 of 1 people found this helpful