javax.ejb.EJBException java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName

会有一股神秘感。 提交于 2019-12-06 05:44:07
unwichtich

The obvious problem is that you didn't specify a jta-data-source and the transaction-type in your persistence.xml.

A jta-data-source is specified like this:

  <persistence-unit name="Hospital">
    <jta-data-source>jdbc/sample</jta-data-source>
  </persistence-unit>

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.

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 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">

See also:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!