Search code examples
mysqljpajakarta-eeapache-tomee

How configure TomEE and JPA


sorry for my bad english, (Im french :-D). I want work with TomEE for JPA, but my configuration is bad i think. I receive a exception when i try to connecte to my database (Mysql).

persistence.xml

<persistence-unit name="elevage" transaction-type="JTA">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <jta-data-source>elevage</jta-data-source>
    <non-jta-data-source>elevageUnmanaged</non-jta-data-source>

    <class>com.test.ejb.BeanAnimal</class>

    <properties>

        <property name="openjpa.jdbc.DBDictionary" value="mysql" />
        <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO" />
    </properties>

</persistence-unit>

tomee.xml

<Resource id="elevage" type="DataSource">
    JdbcDriver          com.mysql.jdbc.Driver
    JdbcUrl             jdbc:mysql://localhost:3306/elevage2?useLegacyDatetimeCode=false&amp;serverTimezone=Australia/Sydney&amp;useSSL=false
    UserName            root
    Password            pass
    JtaManaged          true
    DefaultAutoCommit   false
</Resource>

<Resource id="elevageUnmanaged" type="DataSource">
    JdbcDriver          com.mysql.jdbc.Driver
    JdbcUrl             jdbc:mysql://localhost:3306/elevage2?useLegacyDatetimeCode=false&amp;serverTimezone=Australia/Sydney&amp;useSSL=false
    UserName            root
    Password            pass
    JtaManaged          false
</Resource>

Exception

AVERTISSEMENT: Unexpected exception from beforeCompletion; transaction will roll back 
<openjpa-2.4.1-r422266:1730418 fatal general error> org.apache.openjpa.persistence.PersistenceException: user lacks privilege or object not found: OPENJPA_SEQUENCE_TABLE {SELECT SEQUENCE_VALUE FROM OPENJPA_SEQUENCE_TABLE WHERE ID = ? FOR UPDATE} [code=-5501, state=42501]

Request is a "SELECT" and i want take all data in my database. I have see documentation but the problem persiste.

Thank all for your answer ! (if you need more file, tell me :-) )


Solution

  • After a long time tearing my hair, I found a solution, if it can save time, here it is:

    2 Configurations!

    In development:

    tomee.xml is not used, it is necessary to configure openejb.xml whose path is specified in the eclipse console, attention, the access is by hidden file

    Path for my machine (Linux):

     /home/user/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/conf/openejb.xml
    

    At the bottom of the file, you have section "Resource", the configuration is identical to tomee.xml (you can find documentation at this adress : documentation for configuration tomee.xml

    In production:

    we forget openejb.xml, a configuration is identical but in tomee.xml

    to finish, here is my configuration:

    persistence.xml

    <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="elevage" transaction-type="JTA">
        <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
        <jta-data-source>MyDataBase</jta-data-source>
        <non-jta-data-source>MyDataBaseUnmanaged</non-jta-data-source>
    
        <class>com.test.ejb.BeanAnimal</class>
        <!-- <class>com.test.ejb.BeanUser</class>-->
    
    
        <properties>
            <property name="openjpa.jdbc.DBDictionary" value="mysql" />
            <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO" />
        </properties>
    
    </persistence-unit>
    

    openejb.xml (in development) and tomee.xml (in production)

    <Resource id="MyDataBase" type="DataSource">
        JdbcDriver com.mysql.jdbc.Driver
        JdbcUrl jdbc:mysql://localhost:3306/elevage?useLegacyDatetimeCode=false&amp;serverTimezone=Australia/Sydney&amp;useSSL=false
        UserName root
        Password pass
        JtaManaged true
    </Resource>
    
    <Resource id="MyDataBaseUnmanaged" type="DataSource">
        JdbcDriver com.mysql.jdbc.Driver
        JdbcUrl jdbc:mysql://localhost:3306/elevage?useLegacyDatetimeCode=false&amp;serverTimezone=Australia/Sydney&amp;useSSL=false
        UserName root
        Password pass
        JtaManaged false
    </Resource>