Google guice persist throws error No Persistence provider for EntityManager named test

179 views Asked by At

Hi I searched the web but only find insufficient results. I be happy if you point me to a site that helps. I try to start google guice with guice persist but keep getting the error that No Persistence provider for EntityManager named test is found.

Here my 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="test"
        transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>net.croware.containerize.client.domain.model.User</class>
        <properties>
            <property name="javax.persistence.jdbc.driver"
                value="org.h2.Driver" />
            <property name="javax.persistence.jdbc.url"
                value="jdbc:h2:mem:test" />
            <property name="javax.persistence.jdbc.user"
                value="sa" />
            <property name="javax.persistence.jdbc.password"
                value="" />
            <property name="eclipselink.ddl-generation"
                value="create-tables" />
            <property name="eclipselink.ddl-generation.output-mode"
                value="database" />
        </properties>
    </persistence-unit>
</persistence> 

I try to create an AbstractModule as follows

package net.croware.containerize.client.domain;

import javax.inject.Inject;

import com.google.inject.AbstractModule;
import com.google.inject.Singleton;
import com.google.inject.persist.PersistService;
import com.google.inject.persist.jpa.JpaPersistModule;

public class DatabaseModule extends AbstractModule {

    @Singleton
    public static class JPAInitializer {

        @Inject
        public JPAInitializer(final PersistService service) {
            service.start();
        }
    }

    @Override
    protected void configure() {
        install(new JpaPersistModule("test"));
        bind(JPAInitializer.class).asEagerSingleton();
    }
}

and in the end my pom.xml

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>net.croware</groupId>
        <artifactId>containerize</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>client</artifactId>
    <name>Client of containerize</name>
    <!-- PROPERTIES -->
    <properties>
        <advancedbindings.version>0.4.0</advancedbindings.version>
        <cdiapi.version>2.0.SP1</cdiapi.version>
        <commonsdbcp.version>1.4</commonsdbcp.version>
        <eclipselink.version>3.0.1</eclipselink.version>
        <guice.version>5.0.1</guice.version>
        <h2.version>1.4.200</h2.version>
        <javaxpersistence.version>2.2</javaxpersistence.version>
        <jpro.version>2020.1.6</jpro.version>
        <mvvmfx.version>1.8.0</mvvmfx.version>
        <javafx.version>17-ea+9</javafx.version>
        <password4j.version>1.5.3</password4j.version>
        <shiro.version>1.7.1</shiro.version>
    </properties>
    <!-- DEPENDENCIES -->
    <dependencies>
        <!-- ADVANCED BINDINGS -->
        <dependency>
            <groupId>eu.lestard</groupId>
            <artifactId>advanced-bindings</artifactId>
            <version>${advancedbindings.version}</version>
        </dependency>
        <!-- CDI API -->
        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <version>${cdiapi.version}</version>
        </dependency>
        <!-- ECLIPSELINK -->
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa</artifactId>
            <version>${eclipselink.version}</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.moxy</artifactId>
            <version>${eclipselink.version}</version>
        </dependency>
        <!-- GOOGLE GUICE -->
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>${guice.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.inject.extensions</groupId>
            <artifactId>guice-persist</artifactId>
            <version>${guice.version}</version>
        </dependency>
        <!-- H2 DATABASEENGINE -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>${h2.version}</version>
        </dependency>
        <!-- JAVAFX -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-base</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>${javafx.version}</version>
        </dependency>
        <!-- JAVAX PERSISTENCE -->
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>${javaxpersistence.version}</version>
        </dependency>
        <!-- JPRO -->
        <dependency>
            <groupId>com.sandec.jpro</groupId>
            <artifactId>jpro-webapi</artifactId>
            <version>${jpro.version}</version>
            <scope>compile</scope>
        </dependency>
        <!-- MVVMFX -->
        <dependency>
            <groupId>de.saxsys</groupId>
            <artifactId>mvvmfx</artifactId>
            <version>${mvvmfx.version}</version>
        </dependency>
        <dependency>
            <groupId>de.saxsys</groupId>
            <artifactId>mvvmfx-guice</artifactId>
            <version>${mvvmfx.version}</version>
        </dependency>
        <!-- PASSWORD4J -->
        <dependency>
            <groupId>com.password4j</groupId>
            <artifactId>password4j</artifactId>
            <version>${password4j.version}</version>
        </dependency>
        <!-- SHIRO -->
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-core</artifactId>
            <version>${shiro.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.shiro</groupId>
            <artifactId>shiro-guice</artifactId>
            <version>${shiro.version}</version>
        </dependency>
    </dependencies>
    <!-- BUILD -->
    <build>
        <plugins>
            <plugin>
                <groupId>com.sandec.jpro</groupId>
                <artifactId>jpro-maven-plugin</artifactId>
                <version>${jpro.version}</version>
                <configuration>
                    <visible>false</visible>
                    <JVMArgs>
                        <!-- <JVMArg>your-args</JVMArg> -->
                    </JVMArgs>
                    <mainClassName>net.croware.containerize.client.App</mainClassName>
                    <openingPath>/</openingPath>
                </configuration>
            </plugin>
            <!-- -->
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.6</version>
                <configuration>
                    <mainClass>net.croware.containerize.client.App</mainClass>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/classes/</outputDirectory>
                            <encoding>UTF-8</encoding>
                            <resources>
                                <resource>
                                    <directory>src/main/java/</directory>
                                    <filtering>false</filtering>
                                    <includes>
                                        <include>**/*.fxml</include>
                                    </includes>
                                </resource>
                                <resource>
                                    <directory>src/main/resources</directory>
                                    <filtering>false</filtering>
                                    <includes>
                                        <include>**/.*</include>
                                    </includes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <!-- PLUGIN REPOSITORIES -->
    <pluginRepositories>
        <pluginRepository>
            <id>jpro - sandec repository</id>
            <url>https://sandec.jfrog.io/artifactory/repo</url>
        </pluginRepository>
    </pluginRepositories>
    <!-- REPOSITORIES -->
    <repositories>
        <repository>
            <id>jpro - sandec repository</id>
            <url>https://sandec.jfrog.io/artifactory/repo</url>
        </repository>
    </repositories>
</project>

help is much appreciated. regards Chris

1

There are 1 answers

0
Christian Rocholl On

Hi it seems that eclipselink 3.0.1 is buggy. I downgraded to 2.5.1 and now everything seems to work regards Chris