且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

javax.ejb.EJBException java.lang.IllegalStateException:无法检索unitName的EntityManagerFactory

更新时间:2022-01-23 21:52:51

显而易见的问题是,您没有在persistence.xml中指定jta-data-sourcetransaction-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">

另请参见: