0

I have the follow problem:

I've created an application divided in three layers, every layer has his own maven project:

· Persistence layer has only entities and DAO classes

· Domain layer has the bussiness classes and WebServices

· UI layer has the WEB

Every layer is managed with maven, and Domain depends on Persistence layer

If I run the Persistence layer, everything works fine, as it should, (Running JUnit test)

But when I add the dependency in Domain layer, can't run throwing a PersistenceException, it seems as maven don't export the persistence to de Domain project.

This is the POM for Persistence layer:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>gamerscreed.rocketstats</groupId>
<artifactId>RocketStatsCore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>RocketStatsCore</name>
<dependencies>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.40</version>
    </dependency>       
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.3.Final</version>
    </dependency>   
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.3.0.Final</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>

</dependencies>
<build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
        <resource>
            <directory>src</directory>
            <includes>
                <include>META-INF/persistence.xml</include>
            </includes>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

And this is the pom for Domain layer:

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>gamerscreed.rocketstats</groupId>
<artifactId>RocketStatsDomain</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>RocketStatsDomain</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.5.RELEASE</version>
    <relativePath />
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>gamerscreed.rocketstats</groupId>
        <artifactId>RocketStatsCore</artifactId>
    </dependency>

    <dependency>
        <groupId>gamerscreed.profiler</groupId>
        <artifactId>GamersCreedShared</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>gamerscreed.rocketstats</groupId>
            <artifactId>RocketStatsCore</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
</dependencyManagement>

And here is the Exception thrown:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'playerBusinessLayer' defined in file [C:\Users\Xelit3\Documents\Eclipse workspace\git\GamersCreed\RocketStatsDomain\target\classes\gamerscreed\rocketstats\domain\implementation\PlayerBusinessLayer.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [gamerscreed.rocketstats.domain.implementation.PlayerBusinessLayer]: Constructor threw exception; nested exception is javax.persistence.PersistenceException: No Persistence provider for EntityManager named RocketStats

I've see this thread but nothing here helped me:

Thanks in advance

EDIT: Added persistence.xml:

<?xml version="1.0" encoding="UTF-8" ?> <persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="RocketStats" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

    <class>gamerscreed.rocketstats.model.dto.Match</class>
    <class>gamerscreed.rocketstats.model.dto.MatchResultPlayer</class>
    <class>gamerscreed.rocketstats.model.dto.MatchResultPlayerPK</class>
    <class>gamerscreed.rocketstats.model.dto.MatchType</class>
    <class>gamerscreed.rocketstats.model.dto.Player</class>
    <class>gamerscreed.rocketstats.model.dto.Result</class>
    <class>gamerscreed.rocketstats.model.dto.Role</class>
    <class>gamerscreed.rocketstats.model.dto.Team</class>
    <class>gamerscreed.rocketstats.model.dto.Tournament</class>

    <validation-mode>AUTO</validation-mode>

    <properties>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
        <property name="javax.persistence.jdbc.user" value="chustasoft" />
        <property name="javax.persistence.jdbc.password" value="chustaK4" />
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/cs_rocketstats" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
        <property name="hibernate.max_fetch_depth" value="3" />
        <property name="show_sql" value="true"></property>
    </properties>

</persistence-unit>

Community
  • 1
  • 1
Xelit3
  • 228
  • 4
  • 19
  • Define "Maven doesn't export persistence.xml". If you put _persistence.xml_ under somewhere like src/main/resources/META-INF then it is visible when running an application with Maven. Why base things in supposition ("it seems like") when you can run Maven with --debug and see where things are – Neil Stockton Nov 05 '16 at 10:59
  • Thanks for your interest, I'm doing from eclipse, maybe i haven't knowledge enough but i didn't understand what you mean to say with "run maven with debug" I'm just debugging the app and this is the problem I have :S Thanks – Xelit3 Nov 05 '16 at 11:58
  • I have to say that _persistence.xml_ it's under src\META-INF, but it's how it's working now. If the path it's a problem how can I change without stop working? Thanks again – Xelit3 Nov 05 '16 at 12:04

1 Answers1

1

Look like persistence provider is missing/not found in classpath from persistence.xml.

<provider>PersistenceProviderImpl</provider>
<jta-data-source>..</jta-data-source>
<non-jta-data-source>..</non-jta-data-source>
<class></class>

<properties>
    <property name="openjpa.jdbc.SynchronizeMappings" value="validate" />            
</properties>

sahoora
  • 245
  • 1
  • 5
  • Thanks for your reply, but I have the provider declared inside the persistence.xml. As I've said before, If I run the test from Infraestructure layer, everything works well, but fails when I'm running from Domain layer. I've edited my question and added the persistence.xml, ¿do you find something bad? Thank you so much for your reply and your interest – Xelit3 Nov 05 '16 at 11:53
  • I have to say that persistence.xml it's under src\META-INF, but it's how it's working now. If the path it's a problem how can I change without stop working? Thanks again – Xelit3 Nov 05 '16 at 12:05
  • Infrastructure layer should access the real provider exposed by src/main/resources src ----main --------resources ------------------META-INF/persistence.xml --------java/your code Domain/Local layer should access the test provider exposed by src/main/resources like RESOURCE_LOCAL src ----test --------resources ------------------META-INF/persistence.xml --------java/your code Hope this clarifies your doubts. When you added under src/META-INF, it is available to both domain and infrastructure layer – sahoora Nov 05 '16 at 12:13
  • thanks so much, yes now it's working, you've clarified my boubts, thanks! – Xelit3 Nov 06 '16 at 19:44