persistence.xml transaction-type =“JTA”

时间:2013-09-16 16:50:00

标签: java xml persistence openjpa jta

这个perisistence.xml文件是否正确,尤其是当我transaction-type="JTA"

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
<persistence-unit name="CollDocPU" transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>model.entity.StudentAddSolution</class>
<class>model.entity.Lecturer</class>
<class>model.entity.Solution</class>
<class>model.entity.Student</class>
<class>model.entity.Course</class>
<class>model.entity.File</class>
<class>model.entity.CourseHasLecturer</class>
<class>model.entity.Mail</class>
<class>model.entity.StudentAtCourse</class>
<class>model.entity.Roles</class>
<class>model.entity.Task</class>
<class>model.entity.User</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
  <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:11080/myBase?zeroDateTimeBehavior=convertToNull"/>
  <property name="javax.persistence.jdbc.password" value="pass,"/>
  <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
  <property name="javax.persistence.jdbc.user" value="myBase"/>
  <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
</properties>

2 个答案:

答案 0 :(得分:1)

您收到错误了吗?

如果您使用的是JTA,我建议您使用DataSource作为连接的提供者。

如:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
<persistence-unit name="CollDocPU" transaction-type="JTA">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>datasource</jta-data-source> 
<class>model.entity.StudentAddSolution</class>
<class>model.entity.Lecturer</class>
<class>model.entity.Solution</class>
<class>model.entity.Student</class>
<class>model.entity.Course</class>
<class>model.entity.File</class>
<class>model.entity.CourseHasLecturer</class>
<class>model.entity.Mail</class>
<class>model.entity.StudentAtCourse</class>
<class>model.entity.Roles</class>
<class>model.entity.Task</class>
<class>model.entity.User</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
</persistence-unit>

</persistence>

顺便说一下,你需要关闭所有你的标签

此致

答案 1 :(得分:0)

我的朋友,也许这是另一个错误,试试这个,按照我告诉你的方式,只需按System.out.println打印EntityManager(em.toString());如果你得到的东西,那是因为没关系,你在其他方法中得到的nullpointer可以是程序逻辑