更新时间:2022-01-23 21:52:51
显而易见的问题是,您没有在persistence.xml
中指定jta-data-source
和transaction-type
.
The obvious problem is that you didn't specify a jta-data-source
and the transaction-type
in your persistence.xml
.
像这样指定jta-data-source
:
<persistence-unit name="Hospital">
<jta-data-source>jdbc/sample</jta-data-source>
</persistence-unit>
您必须在Glassfish实例中创建JDBC资源.为此,请在http://localhost:4848
下打开Glassfish Admin GUI,然后在Resources
-> JDBC Connection Pools
下创建一个连接池.然后在Resources
-> JDBC Resources
下创建一个名为jdbc/sample
的 JDBC资源,并使其引用新的连接池.
You have to create the JDBC resource in your Glassfish instance. To do this open the Glassfish Admin GUI under http://localhost:4848
and create a Connection Pool under Resources
-> JDBC Connection Pools
. Then create a JDBC resource under Resources
-> JDBC Resources
named jdbc/sample
and make it reference the new connection pool.
此外,服务器似乎以某种方式认为您要使用transaction-type
RESOURCE_LOCAL
,这要求您指定EntityManagerFactory
以获得EntityManager
的实例.
Further, it looks like the server somehow thinks that you want to use transaction-type
RESOURCE_LOCAL
which requires that you specify an EntityManagerFactory
to get an instance of the EntityManager
.
JTA
应该是默认的transaction-type
,但是您可能必须像这样在persistence.xml
中明确指定transaction-type
:
JTA
should be the default transaction-type
in a Java EE environment but you may have to explicitly specifiy the transaction-type
in the persistence.xml
like this:
<persistence-unit name="Hospital" transaction-type="JTA">
另请参见: