2

Is this perisistence.xml file correct, especially when i 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>

kuba44
  • 1,838
  • 9
  • 34
  • 62

2 Answers2

4

Are you getting an error?

If you are using JTA I will suggest you use a DataSource as a provider of your connections.

Such as:

<?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>

BTW, you need to close all yours tags

Regards

Daniel Hernández
  • 4,078
  • 6
  • 27
  • 38
  • how can i use DataSource as a provider of my connections ? i'm sorry but i'm new and don't understend everything – kuba44 Sep 16 '13 at 17:04
  • In the way you were working, I think you would use RESOURCE_LOCA as transaction-type – Daniel Hernández Sep 16 '13 at 17:06
  • but when i use "RESOURCE_LOCA" i have error: ` java.lang.NullPointerException at model.beans.UserFacade.findByLogin(UserFacade.java:34)` and when i use `JTA` i have error: `Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException - type not found or user lacks privilege: TEXT {stmnt 1013050998 CREATE TABLE COURSE (id_course SMALLINT NOT NULL, code VARCHAR(255), description TEXT, name VARCHAR(255), realization INTEGER, version SMALLINT, PRIMARY KEY (id_course)) ENGINE = innodb} [code=-5509, state=42509] at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecora` – kuba44 Sep 16 '13 at 17:07
  • i get EnitityManager by @EJB annotation i managed Bean in my application – kuba44 Sep 16 '13 at 17:13
  • 1
    How can you get an EntityManager by @EJB annotation? If you are using EM in an EJB you would use PersistenceContext to retrieve an entityManager – Daniel Hernández Sep 16 '13 at 17:15
  • i'm sorry, you are right. I get EM by `@PersistenceContext(unitName = "CollDocPU")` – kuba44 Sep 16 '13 at 17:18
  • Removing `openjpa.jdbc.SynchronizeMappings` didn't help – kuba44 Sep 16 '13 at 17:22
  • After remote, get the entityManaget by this way: EntityManagerFactory emf = Persistence.createEntityManagerFactory("CollDocPU"); EntityManager em = emf.createEntityManager(); – Daniel Hernández Sep 16 '13 at 17:27
  • 1
    As I told you, before doing this: EntityManagerFactory emf = Persistence.createEntityManagerFactory("CollDocPU"); EntityManager em = emf.createEntityManager(); Just print the em by System.out and tell me what you get – Daniel Hernández Sep 16 '13 at 17:59
0

My friend, Maybe that is another error, try this, after doing what I told you, just print the EntityManager by System.out.println(em.toString()); If you are getting something, It is because It is OK, the nullpointer that you are getting in the other method could be by the program logic

Daniel Hernández
  • 4,078
  • 6
  • 27
  • 38