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

    Howto JBoss AS7 and Spring Data JPA

    Malte Pickhan Newbie

      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)

       

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

       

      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"
          xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
          http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
      
          <persistence-unit name="persistenceUnit" transaction-type="JTA">
              <jta-data-source>java:/myDS</jta-data-source>
              <class>de.company.project.client.domain.User</class>
                <properties>
                  <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"/> 
              </properties>
      
          </persistence-unit>
      
      </persistence>
      

       

      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,

       

      Malte