抱歉我的英语不好,(法语:-D)。我想和TomEE一起为JPA工作,但我认为我的配置很糟糕。当我尝试连接到我的数据库(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>
我们是
<Resource id="elevage" type="DataSource">
JdbcDriver com.mysql.jdbc.Driver
JdbcUrl jdbc:mysql://localhost:3306/elevage2?useLegacyDatetimeCode=false&serverTimezone=Australia/Sydney&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&serverTimezone=Australia/Sydney&useSSL=false
UserName root
Password pass
JtaManaged false
</Resource>
例外
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]
请求是一个“SELECT”,我想要获取我的数据库中的所有数据。我看到文档,但问题仍然存在。
谢谢大家的回答! (如果你需要更多文件,请告诉我:-))
经过很长一段时间撕裂我的头发,我找到了一个解决方案,如果可以节省时间,这里是:
2配置!
开发中:
没有使用tomee.xml,有必要配置openejb.xml,其路径是在eclipse控制台中指定的,注意,访问是通过隐藏文件
我的机器的路径(Linux):
/home/user/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/conf/openejb.xml
在文件的底部,您有“资源”部分,配置与tomee.xml相同(您可以在此地址找到文档:documentation for configuration tomee.xml
在生产中:
我们忘记了openejb.xml,配置是相同的但是在tomee.xml中
完成,这是我的配置:
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(开发中)和tomee.xml(生产中)
<Resource id="MyDataBase" type="DataSource">
JdbcDriver com.mysql.jdbc.Driver
JdbcUrl jdbc:mysql://localhost:3306/elevage?useLegacyDatetimeCode=false&serverTimezone=Australia/Sydney&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&serverTimezone=Australia/Sydney&useSSL=false
UserName root
Password pass
JtaManaged false
</Resource>