[PersistenceUnit:< name>]:无法构建EntityManagerFactory [英] [PersistenceUnit: <name>]: unable to build EntityManagerFactory

查看:175
本文介绍了[PersistenceUnit:< name>]:无法构建EntityManagerFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如在主题上所述,我的问题是无法构建 EntityManagerFactory 。我正在使用Maven + Hibernate。我连接到一个MySQL数据库(< jdbc:// mysql:// localhost:3306 /< dbname> )。

这里奇怪的是在Eclipse中调试时,它工作正常。但是当我使用Maven构建它时,JAR文件正在抛出这样的错误。我已经检查过Manifest文件,并且所有必需的JAR都包含在Class-Path中。以下是控制台中显示的JAR错误:



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

  2012年2月3日下午5:01:16 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
Feb 3,2012 5:01:16 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO:HHH000021:字节码提供程序名称:javassist
Feb 3,2012 5:01:16 PM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO:HHH000402:使用Hibernate内置连接池(不适合生产使用!)
Feb 3,2012 5:01:16 PM class< name>。< name>。< name> <名称>
SEVERE:[错误]:[PersistenceUnit:< name>]无法构建EntityManagerFactory
[错误]:[PersistenceUnit:< name>]无法构建EntityManagerFactory

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



下面是我的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>
<属性>
<! - < property name =hibernate.ejb.cfgfilevalue =/ classifyPE.cfg.xml/> - >
< property name =hibernate.connection.driver_classvalue =com.mysql.jdbc.Driver/>
< property name =hibernate.connection.passwordvalue =< value> />
< property name =hibernate.connection.urlvalue =jdbc:mysql:// localhost:3306 /< name> />
< property name =hibernate.connection.usernamevalue =root/>
< property name =hibernate.dialectvalue =org.hibernate.dialect.MySQLDialect/>
< / properties>
< / persistence-unit>
< /余辉>

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



我在这里做错了什么?或者我缺乏什么?

如前所述,它正在处理Debug。但是,当我把它打包成JAR时,(所有必需的JAR出现在libs文件夹中),它不是。

解决方案

add这在你的xml文件中

 < property name =javax.persistence.validation.mode> none< / property> 


As stated on the subject, my problem is the EntityManagerFactory cannot be built. I am using Maven + Hibernate. I am connecting to a MySQL DB (<jdbc://mysql://localhost:3306/<dbname>).

The weird thing here is during debugging in Eclipse, it is working fine. But when I build it using Maven build, the JAR file is throwing such error. I checked the Manifest file already and all the necessary JARs were included in the Class-Path. Below is the error of the JAR displayed in 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 lacking?
As mentioned, it's working on Debug. But when I package it into JAR,(with all the necessary JARs present in the libs folder), it's not.

解决方案

add this in your xml file

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

这篇关于[PersistenceUnit:&lt; name&gt;]:无法构建EntityManagerFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆