我已经尝试了几种建议的方法来解决这个java持久性异常,但还没有成功。任何建议或帮助将不胜感激。
以下是详情
SQLQueries.xml
-----------------------------
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings
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/orm_2_0.xsd "
version="2.0">
<sql-query name="GET_NEXT_NUM_SP" callable="true">
<return alias = "nextNumber" class="com.utility.numbergenerator.da.NumberDAOImpl">
<return-property name="nextSeqNum" column="NEXT_SEQ_NUM" />
</return>
{ ? = call Test_Proc }
</sql-query>
</entity-mappings>
persistence.xml
-----------------------
<?xml version="1.0" encoding="UTF-8"?>
<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_2_0.xsd"
version="2.0">
<persistence-unit name="NG" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<mapping-file>META-INF/SQLQueries.xml</mapping-file>
<class> Several related classes </class>
<properties> Followed by properties </properties>
</persistence-unit>
- 初始化数据库连接 - javax.persistence.PersistenceException:[PersistenceUnit:NG]读取JPA XML文件时出错:META-INF / SQLQueries.xml 在org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:1205) 在org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1004) 在org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:282) 在org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:366) 在org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56) 在javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48) 在javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32) 在com.go2uti.oneworld.common.hibernate.HibernateUtil.initializeJPA(HibernateUtil.java:68) 在com.go2uti.oneworld.common.hibernate.HibernateUtil。(HibernateUtil.java:38) 在com.go2uti.oneworld.utility.businessidgenerator.da.EntityManagerFactorySingleton.init(EntityManagerFactorySingleton.java:26) 在com.go2uti.oneworld.utility.businessidgenerator.compatibility.AbstractPersistentTest.initializeContext(AbstractPersistentTest.java:38) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) 在org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:45) 在org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 在org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) 在org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27) 在org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) 在org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) 在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) 在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) 在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:231) 在org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:60) 在org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) 在org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:50) 在org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:222) 在org.junit.runners.ParentRunner.run(ParentRunner.java:300) 在org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 在org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 引起:org.hibernate.InvalidMappingException:无法读取XML 在org.hibernate.util.xml.MappingReader.readMappingDocument(MappingReader.java:101) 在org.hibernate.cfg.Configuration.add(Configuration.java:513) 在org.hibernate.cfg.Configuration.add(Configuration.java:509) 在org.hibernate.cfg.Configuration.add(Configuration.java:716) 在org.hibernate.cfg.Configuration.addResource(Configuration.java:801) 在org.hibernate.cfg.AnnotationConfiguration.addResource(AnnotationConfiguration.java:152) 在org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:1192) ......还有34个
请帮我解决这个问题。
答案 0 :(得分:0)
您的META-INF/SQLQueries.xml
文件基于JPA 2.0 XML映射架构,该架构由http://java.sun.com/xml/ns/persistence/orm_2_0.xsd定义。
由于sql-query
元素是特定于Hibernate的,因此您需要将<entity-mappings>
替换为<hibernate-mapping>
,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<sql-query name="GET_NEXT_NUM_SP" callable="true">
<return alias="nextNumber" class="com.utility.numbergenerator.da.NumberDAOImpl">
<return-property name="nextSeqNum" column="NEXT_SEQ_NUM" />
</return>
{ ? = call Test_Proc }
</sql-query>
</hibernate-mapping>