Tome Jpa 设置
Tomee jpa settings
无法部署应用程序,出现异常 java.lang.Exception:持久性单元:持久性 -750441533localhost:找不到名称 "openejb/PersistenceUnit/persistence -750441533localhost"。
尝试了很多配置。有什么设置建议吗?
坚持。xml
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="persistence">
<description>Hibernate JPA</description>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>jdbc/postgres</non-jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
</properties>
</persistence-unit>
</persistence>
context.xml
<Context antiJARLocking="true" path="/postgres">
<Resource name="jdbc/postgres"
auth="Container"
type="javax.sql.DataSource"
username="root"
password="root"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/base"
maxTotal="20"
maxActive="25"
maxIdle="3"/>
</Context>
错误
org.apache.catalina.LifecycleException: An invalid Lifecycle transition was attempted ([before_destroy]) for component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]] in state [STARTING_PREP]
14-Jun-2019 17:21:36.774 SEVERE [http-nio-8080-exec-4]
org.apache.openejb.assembler.classic.Assembler.destroyApplication
undeployException original cause
java.lang.Exception: deployment not found: .Comp1964794492
14-Jun-2019 17:21:36.777 SEVERE [http-nio-8080-exec-4]
org.apache.openejb.assembler.classic.Assembler.destroyApplication
undeployException original cause
java.lang.Exception: persistence-unit: persistence
-750441533localhost: Name "openejb/PersistenceUnit/persistence
-750441533localhost" not found.
org.apache.openejb.OpenEJBRuntimeException: javax.persistence.PersistenceException: [PersistenceUnit: persistence] Unable to build Hibernate SessionFactory: javax.persistence.PersistenceException: [PersistenceUnit: persistence] Unable to build Hibernate SessionFactory
我找到了解决方案。 tomee 的 Jta 配置:
main/resourses/META-INF/persistence.xml
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="persistence" transaction-type="JTA">
<description>persistence</description>
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>MyDataSource</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create" />
</properties>
</persistence-unit>
tomee\conf\tomee.xml
<?xml version="1.0" encoding="UTF-8"?>
<tomee>
<!-- see http://tomee.apache.org/containers-and-resources.html -->
<!-- activate next line to be able to deploy applications in apps -->
<!-- <Deployments dir="apps" /> -->
<Resource id="MyDataSource" type="javax.sql.DataSource">
JdbcDriver org.postgresql.Driver
JdbcUrl jdbc:postgresql://localhost:5432/dbname
UserName un
Password pass
JtaManaged true
DefaultAutoCommit true
</Resource>
</tomee>
Eclipselink 专家:
https://mvnrepository.com/artifact/org.eclipse.persistence/org.eclipse.persistence.jpa
不记得把jdbc驱动.jar放到tomee\lib.
另请注意,eclipselink 仅适用于 tomee plume。
无法部署应用程序,出现异常 java.lang.Exception:持久性单元:持久性 -750441533localhost:找不到名称 "openejb/PersistenceUnit/persistence -750441533localhost"。 尝试了很多配置。有什么设置建议吗?
坚持。xml
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="persistence">
<description>Hibernate JPA</description>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>jdbc/postgres</non-jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
</properties>
</persistence-unit>
</persistence>
context.xml
<Context antiJARLocking="true" path="/postgres">
<Resource name="jdbc/postgres"
auth="Container"
type="javax.sql.DataSource"
username="root"
password="root"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/base"
maxTotal="20"
maxActive="25"
maxIdle="3"/>
</Context>
错误
org.apache.catalina.LifecycleException: An invalid Lifecycle transition was attempted ([before_destroy]) for component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]] in state [STARTING_PREP]
14-Jun-2019 17:21:36.774 SEVERE [http-nio-8080-exec-4]
org.apache.openejb.assembler.classic.Assembler.destroyApplication
undeployException original cause
java.lang.Exception: deployment not found: .Comp1964794492
14-Jun-2019 17:21:36.777 SEVERE [http-nio-8080-exec-4]
org.apache.openejb.assembler.classic.Assembler.destroyApplication
undeployException original cause
java.lang.Exception: persistence-unit: persistence
-750441533localhost: Name "openejb/PersistenceUnit/persistence
-750441533localhost" not found.
org.apache.openejb.OpenEJBRuntimeException: javax.persistence.PersistenceException: [PersistenceUnit: persistence] Unable to build Hibernate SessionFactory: javax.persistence.PersistenceException: [PersistenceUnit: persistence] Unable to build Hibernate SessionFactory
我找到了解决方案。 tomee 的 Jta 配置:
main/resourses/META-INF/persistence.xml
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="persistence" transaction-type="JTA">
<description>persistence</description>
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>MyDataSource</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create" />
</properties>
</persistence-unit>
tomee\conf\tomee.xml
<?xml version="1.0" encoding="UTF-8"?>
<tomee>
<!-- see http://tomee.apache.org/containers-and-resources.html -->
<!-- activate next line to be able to deploy applications in apps -->
<!-- <Deployments dir="apps" /> -->
<Resource id="MyDataSource" type="javax.sql.DataSource">
JdbcDriver org.postgresql.Driver
JdbcUrl jdbc:postgresql://localhost:5432/dbname
UserName un
Password pass
JtaManaged true
DefaultAutoCommit true
</Resource>
</tomee>
Eclipselink 专家:
https://mvnrepository.com/artifact/org.eclipse.persistence/org.eclipse.persistence.jpa
不记得把jdbc驱动.jar放到tomee\lib.
另请注意,eclipselink 仅适用于 tomee plume。