hibernate - Unable to make a Persistence provider for EntityManager connection (Glassfish / Mysql / Maven) -
i'm new java ee 7. , i'm stuck making persistence connection.
it turned out error i'm running common. have tried suggested solutions. apparently i'm still doing wrong. see mistake made.
glassfish 4.1, maven, mysql 5.1.44 , use netbeans 8.2.
when run test class. following exception:
exception in thread "main" javax.persistence.persistenceexception: no persistence provider entitymanager named test6_mysql @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:61) @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:39) @ com.mycompany.simpleform5.test.main(test.java:25)
i have tried different solutions suggested in:
i have implemented instructions explained in: no persistence provider entitymanager named --> i’ve changed "hibernate-entitymanager.jar" newer version: "hibernate-core.jar".
i have tried other older persistence versions 1.0 , 2.0.
i have changed org.hibernate.ejb.hibernatepersistence: (https://stackoverflow.com/a/1285436/784594).
i used hibernate-core-5.2.2.final.jar (hibernate 5.2.2: no persistence provider entitymanager). didn't work.
the java class:
public class test { public static void main (string[] args) { [..] entitymanagerfactory emf = persistence.createentitymanagerfactory("test6_mysql"); entitymanager em = emf.createentitymanager(); [..] } }
meta-inf/persistence.xml
<?xml version="1.0" encoding="utf-8"?> <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" version="2.1"> <persistence-unit name="test6_mysql"> <provider>org.hibernate.jpa.hibernatepersistenceprovider</provider> <class>com.mycompany.simpleform6</class> <properties> <property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.driver" /> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/so_database" /> <property name="javax.persistence.jdbc.user" value="root" /> <property name="javax.persistence.jdbc.password" value="admin" /> <property name="hibernate.show_sql" value="true" /> <property name="hibernate.hbm2ddl.auto" value="update" /> </properties> </persistence-unit> </persistence>
the pom.xml
<?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>com.mycompany</groupid> <artifactid>simpleform6</artifactid> <version>1.0-snapshot</version> <packaging>war</packaging> <name>simpleform6</name> <properties> <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> <project.build.sourceencoding>utf-8</project.build.sourceencoding> </properties> <dependencies> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.44</version> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-jpamodelgen</artifactid> <version>5.1.5.final</version> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-entitymanager</artifactid> <version>5.2.10.final</version> <exclusions> <exclusion> <groupid>org.hibernate</groupid> <artifactid>hibernate-core</artifactid> </exclusion> </exclusions> </dependency> <dependency> <groupid>org.jboss.logging</groupid> <artifactid>jboss-logging</artifactid> <version>3.3.1.final</version> </dependency> <dependency> <groupid>javax</groupid> <artifactid>javaee-web-api</artifactid> <version>7.0</version> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> <compilerarguments> <endorseddirs>${endorsed.dir}</endorseddirs> </compilerarguments> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-war-plugin</artifactid> <version>2.3</version> <configuration> <failonmissingwebxml>false</failonmissingwebxml> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-dependency-plugin</artifactid> <version>2.6</version> <executions> <execution> <phase>validate</phase> <goals> <goal>copy</goal> </goals> <configuration> <outputdirectory>${endorsed.dir}</outputdirectory> <silent>true</silent> <artifactitems> <artifactitem> <groupid>javax</groupid> <artifactid>javaee-endorsed-api</artifactid> <version>7.0</version> <type>jar</type> </artifactitem> </artifactitems> </configuration> </execution> </executions> </plugin> </plugins> </build> <repositories> <repository> <id>unknown-jars-temp-repo</id> <name>a temporary repository created netbeans libraries , jars not identify. please replace dependencies in repository correct ones , delete repository.</name> <url>file:${project.basedir}/lib</url> </repository> </repositories> </project>
Comments
Post a Comment