JPA没有';使用JTA时找不到实体
我使用JPA,我想使用JTA DataSource和JNDI设置正确且正常工作,但如果数据库 为空(尚未创建表)JTA不工作 这就是我的意思。如果我使用以下persistence.xml:JPA没有';使用JTA时找不到实体,jpa,jta,Jpa,Jta,我使用JPA,我想使用JTA DataSource和JNDI设置正确且正常工作,但如果数据库 为空(尚未创建表)JTA不工作 这就是我的意思。如果我使用以下persistence.xml: <?xml version="1.0" encoding="UTF-8" ?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-in
<?xml version="1.0" encoding="UTF-8" ?>
<persistence 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_1_0.xsd"
version="1.0">
<persistence-unit name="MyUnit" transaction-type="JTA">
<jta-data-source>jdbc/MyDB</jta-data-source>
<class>de.MyEntity</class>
</persistence-unit>
</persistence>
jdbc/MyDB
MyEntity酒店
它说我的实体不是一个实体。实体管理员找不到它
如果我使用此persistence.xml构建数据库并导入数据:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence 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_1_0.xsd"
version="1.0">
<persistence-unit name="MyUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>de.MyEntity</class>
<properties>
<property name="persistence-context.persist-on-commit" value="true"/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/myDatastore" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"></property>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.password" value="admin" />
<property name="hibernate.connection.username" value="admin" />
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
org.hibernate.ejb.HibernatePersistence
MyEntity酒店
它工作得很好!如果我现在切换回上面的persistence.xml来使用
JTA突然间,他发现我的实体是实体管理者的实体
那么这里的意义何在?如果我想使用
entitymanager和jta不起作用,但如果我不使用jta来创建它
当所有东西都被突然创建时,切换回jta,我可以使用jta
他没有抱怨