Hibernate javax.naming.NameNotFoundException:Name';经理1工厂';在上下文中找不到'';
我得到了错误Hibernate javax.naming.NameNotFoundException:Name';经理1工厂';在上下文中找不到'';,hibernate,jboss7.x,Hibernate,Jboss7.x,我得到了错误 javax.naming.NameNotFoundException: Name 'Manager1Factory' not found in context '' 当我尝试在JBoss7中部署hibernate应用程序时。引发此异常的代码行如下所示 entityManagerFactory = (EntityManagerFactory)ctx.lookup("java:/Manager1Factory"); EntityManager entityManager =
javax.naming.NameNotFoundException: Name 'Manager1Factory' not found in context ''
当我尝试在JBoss7中部署hibernate应用程序时。引发此异常的代码行如下所示
entityManagerFactory = (EntityManagerFactory)ctx.lookup("java:/Manager1Factory");
EntityManager entityManager = entityManagerFactory.createEntityManager();
我在persistence.xml中定义了JNDI名称,如
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="primary2">
<!-- If you are running in a production environment, add a managed
data source, the example data source is just for proofs of concept! -->
<!-- We may want to make this a jta-data-source and let the container create entityManagers/look up EntityManagers via JNDI in our business objs -->
<non-jta-data-source>java:jboss/datasources/MySqlDS2</non-jta-data-source>
<class>com.mycompany.myapp.anywhere.common.businessobjects.CurrentTransaction</class>
<class>com.mycompany.myapp.anywhere.common.businessobjects.ServerSettings</class>
<class>com.mycompany.myapp.anywhere.common.persistence.HibernateUtil</class>
<properties>
<!-- Properties for Hibernate -->
<!-- <sproperty name="hibernate.hbm2ddl.auto" value="create-drop" /> -->
<!-- <property name="hibernate.show_sql" value="false" /> -->
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.ejb.interceptor.session_scoped" value="com.mycompany.myapp.anywhere.common.persistence.BusinessObjectInterceptor"/>
<property name="jboss.entity.manager.jndi.name" value="java:/Manager1"/>
<property name="jboss.entity.manager.factory.jndi.name" value="java:/Manager1Factory"/>
</properties>
</persistence-unit>
</persistence>
java:jboss/datasources/MySqlDS2
com.mycompany.myapp.anywhere.common.businessobjects.CurrentTransaction
com.mycompany.myapp.anywhere.common.businessobjects.ServerSettings
com.mycompany.myapp.anywhere.common.persistence.HibernateUtil
我不知道为什么会收到这个错误-当我检查JBoss控制台时,我看到名称Manager1Factory显示在JNDI绑定下,所以看起来EntityManagerFactory正在创建,但没有被注入到我的类中?知道为什么会这样吗?谢谢 试试看
<property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/Manager1Factory"/>
java:jboss/Manager1Factory