2015-05-21 72 views
1

在IntelliJ Idea中,我使用JPA 2.1和hibernate 4.3.10 final創建了一個項目。在我創建了一個數據源(測試連接:成功)之後,我從數據庫生成了持久性映射。項目編譯沒有錯誤。當我試圖在JPA控制檯測試一個簡單的SELECT *查詢,它返回以下異常:找不到持久化單元

[2015-05-21 16:01:27] javax.persistence.PersistenceException: Unable to locate persistence units 
[2015-05-21 16:01:27] java.lang.RuntimeException: javax.persistence.PersistenceException: Invalid persistence.xml. 
Error parsing XML [line : -1, column : -1] : cvc-elt.1: Cannot find the declaration of element 'persistence'. 

at org.hibernate.jpa.boot.internal.PersistenceXmlParser.validate(PersistenceXmlParser.java:377) 
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.loadUrl(PersistenceXmlParser.java:310) 
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.parsePersistenceXml(PersistenceXmlParser.java:114) 
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.doResolve(PersistenceXmlParser.java:104) 
at org.hibernate.jpa.boot.internal.PersistenceXmlParser.locatePersistenceUnits(PersistenceXmlParser.java:86) 
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:97) 
at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:88) 
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:69) 
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79) 
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54) 
at com.intellij.jpa.remote.impl.JpaFacadeImpl.createEntityManagerFactory(JpaFacadeImpl.java:16) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:497) 
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323) 
at sun.rmi.transport.Transport$1.run(Transport.java:200) 
at sun.rmi.transport.Transport$1.run(Transport.java:197) 
at java.security.AccessController.doPrivileged(Native Method) 
at sun.rmi.transport.Transport.serviceCall(Transport.java:196) 
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) 
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) 
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$254(TCPTransport.java:683) 
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler$$Lambda$2/4400315.run(Unknown Source) 
at java.security.AccessController.doPrivileged(Native Method) 
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
at java.lang.Thread.run(Thread.java:745) 

下面是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="NewPersistenceUnit"> 
    <provider>org.hibernate.ejb.HibernatePersistence</provider> 
    <class>model.DepartmentEntity</class> 
    <class>model.UserEntity</class> 
    <properties> 
     <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/svgroup"/> 
     <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> 
     <property name="hibernate.archive.autodetection" value="class"/> 
     <property name="hibernate.connection.username" value="root"/> 
     <property name="hibernate.connection.password" value=""/> 
     <property name="hibernate.show_sql" value="true"/> 
     <property name="hibernate.format_sql" value="true"/> 
     <property name="hbm2ddl.auto" value="update"/> 
    </properties> 
</persistence-unit> 
</persistence> 

有人能告訴我如何解決這個問題?我正在尋找並沒有成功

編輯

如果我嘗試從沒有數據庫中創建的實體將部署應用程序部署在wildfly的應用程式閱讀書籍約10小時。但是,如果我嘗試部署應用程序後的實體創建我得到以下錯誤:

2015-05-21 18:13:01,697 INFO [org.hibernate.Version] (ServerService Thread Pool -- 15) HHH000412: Hibernate Core {4.3.7.Final} 
2015-05-21 18:13:01,704 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 15) HHH000206: hibernate.properties not found 
2015-05-21 18:13:01,711 INFO [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 15) HHH000021: Bytecode provider name : javassist 
2015-05-21 18:13:02,183 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC000001: Failed to start service jboss.deployment.unit."SVGZad4_ejb_exploded.rar".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."SVGZad4_ejb_exploded.rar".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment "SVGZad4_ejb_exploded.rar" 
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:166) [wildfly-server-8.2.0.Final.jar:8.2.0.Final] 
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final] 
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final] 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_71] 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_71] 
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_71] 
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration 
at org.jboss.as.connector.deployers.ra.processors.ParsedRaDeploymentProcessor.process(ParsedRaDeploymentProcessor.java:237) 
at org.jboss.as.connector.deployers.ra.processors.ParsedRaDeploymentProcessor.deploy(ParsedRaDeploymentProcessor.java:130) 
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:159) [wildfly-server-8.2.0.Final.jar:8.2.0.Final] 
... 5 more 
Caused by: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration 
at org.jboss.jca.common.metadata.ra.common.ResourceAdapter1516Impl.validate(ResourceAdapter1516Impl.java:352) 
at org.jboss.jca.common.metadata.ra.common.ConnectorAbstractmpl.validate(ConnectorAbstractmpl.java:334) 
at org.jboss.as.connector.deployers.ra.processors.ParsedRaDeploymentProcessor.process(ParsedRaDeploymentProcessor.java:206) 
... 7 more 

2015-05-21 18:13:02,207 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 3) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "SVGZad4_ejb_exploded.rar")]) - failure description: {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"SVGZad4_ejb_exploded.rar\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"SVGZad4_ejb_exploded.rar\".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment \"SVGZad4_ejb_exploded.rar\" 
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration 
Caused by: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration"}} 
2015-05-21 18:13:02,216 ERROR [org.jboss.as.server] (management-handler-thread - 3) JBAS015870: Deploy of deployment "SVGZad4_ejb_exploded.rar" was rolled back with the following failure message: 
{"JBAS014671: Failed services" => {"jboss.deployment.unit.\"SVGZad4_ejb_exploded.rar\".INSTALL" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"SVGZad4_ejb_exploded.rar\".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment \"SVGZad4_ejb_exploded.rar\" 
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration 
Caused by: org.jboss.jca.common.api.validator.ValidateException: IJ010075: The resource adapter metadata must contain either an outbound or inbound configuration"}} 
2015-05-21 18:13:02,301 INFO [org.hibernate.validator.internal.util.Version] (MSC service thread 1-1) HV000001: Hibernate Validator 5.1.3.Final 
2015-05-21 18:13:02,626 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 15) JBAS011410: Stopping Persistence Unit (phase 1 of 2) Service 'SVGZad4_ejb_exploded.rar#NewPersistenceUnit' 
2015-05-21 18:13:02,637 INFO [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015877: Stopped deployment SVGZad4_ejb_exploded.rar (runtime-name: SVGZad4_ejb_exploded.rar) in 422ms 
2015-05-21 18:13:02,640 INFO [org.jboss.as.controller] (management-handler-thread - 3) JBAS014774: Service status report 
JBAS014777: Services which failed to start:  service jboss.deployment.unit."SVGZad4_ejb_exploded.rar".INSTALL 

回答

0

我覺得你的瓶(JPA /休眠)可能是舊的。 你使用什麼罐子?

通常,當您下載類似Hibernate的東西時,它們允許您下載具有此類persistence.xml和其他文件示例的示例項目。

更新 也許應用程序沒有拿起預期的persistence.xml文件? 嘗試在persistence.xml文件中添加一些明顯不正確的無效文本。這樣,這個異常將打印出正在查看的persitence.xml的完整名稱。

+0

JPA 2.1和hibernate 4.3.10 final。他們不老。 Hibernate採用maven。 – Student22b

+0

http://in.relation.to/Bloggers/HibernateORM4310FinalReleased – Mecon

0

我認爲你必須改變你的persistence.xml

下面一行

<property name = "hbm2ddl.auto" value = "update" /> 

可能必須改爲

<property name = "hibernate.hbm2ddl.auto" value = "update" /> 

話,我想你沒有任何密碼您的數據庫

<property name = "hibernate.connection.password" value = "?" /> 

否則,我看不出什麼奇怪的。

相關問題