[PersistenceUnit: <name>]: Unable to create EntityManagerFactory

As pointed out on this topic, my problem is that EntityManagerFactory cannot be created. I am using Maven + Hibernate. I am connecting to MySQL DB ( <jdbc://mysql://localhost:3306/<dbname> ).

The strange thing here is during debugging in Eclipse, it works fine. But when I create it using the Maven assembly, the JAR file throws such an error. I already checked the manifest file and all the necessary JARs were included in the Class-Path. The following is the JAR error displayed on the console:

==================================================== ===========================

 Feb 3, 2012 5:01:16 PM org.hibernate.annotations.common.Version <clinit> INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final} Feb 3, 2012 5:01:16 PM org.hibernate.Version logVersion INFO: HHH000412: Hibernate Core {4.0.1.Final} Feb 3, 2012 5:01:16 PM org.hibernate.cfg.Environment <clinit> INFO: HHH000206: hibernate.properties not found Feb 3, 2012 5:01:16 PM org.hibernate.cfg.Environment buildBytecodeProvider INFO: HHH000021: Bytecode provider name : javassist Feb 3, 2012 5:01:16 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!) Feb 3, 2012 5:01:16 PM class <name>.<name>.<name> <name> SEVERE: [ERROR]: [PersistenceUnit: <name>] Unable to build EntityManagerFactory [ERROR]: [PersistenceUnit: <name>] Unable to build EntityManagerFactory 

==================================================== ===========================

below is my persistence.xml:

 <persistence xmlns="http://java.sun.com/xml/ns/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_1_0.xsd" version="1.0"> <persistence-unit name="<name>"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <class>classname</class> <properties> <!-- <property name="hibernate.ejb.cfgfile" value="/classifyPE.cfg.xml"/> --> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" /> <property name="hibernate.connection.password" value="<value>" /> <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/<name>" /> <property name="hibernate.connection.username" value="root" /> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> </properties> </persistence-unit> </persistence> 

==================================================== ===========================

What am I doing wrong here? Or what am I missing?
As already mentioned, he is working on Debug. But when I pack it in a JAR (with all the necessary JAR files present in the libs folder), it is not.

+6
source share
4 answers

add this to your xml file

 <property name="javax.persistence.validation.mode">none</property> 
+3
source

<class>classname</class>

I suspect that your entity is not named by the class name, so try specifying the full class name (for example, foo.bar.realclassname with the name realclassname being the name of your entity class).

+2
source

The persistence.xml file must be located in the META-INF folder in the root bank. Check if he is or not. I assume this is a classpath related issue.

0
source

Try renaming the persistence block. This is important because the name is used to identify the storage unit associated with each EntityManager.

So:

 <persistence-unit name="<name>"> 

should be replaced (for example):

 <persistence-unit name="myUnit"> 
0
source

Source: https://habr.com/ru/post/907553/


All Articles