我的项目在 Glassfish 3.0.1 上运行我正在尝试使用 @PersistenceContext 注释来注入 EntityManager。这是我的代码:
@Stateless
public class UserBean implements UserBeanRemote {
@PersistenceContext(unitName = "RHDManagementPlatformPU")
private EntityManager em;
public UserBean() {
if (this.em == null) {
System.err.println("NULL");
}
}
...
}
在控制台中,我收到错误消息“NULL”。我已经看到了 5-6 个与我相似的主题。但我唯一理解的是问题可能出在我的persistence.xml 中。就这个:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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">
<persistence-unit name="RHDManagementPlatformPU" transaction-type="JTA">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<jta-data-source>dev_magi_entities</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="toplink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
我试图在互联网上找到如何配置此文件,但没有找到问题所在。也许有人有任何想法或教程,手动链接可以帮助我更好地理解这个野兽是如何工作的=)