javax.naming.NameNotFoundException:名称“Manager1Factory”在上下文中找不到''

发布于 2024-12-05 13:57:54 字数 2447 浏览 0 评论 0原文

当我尝试在 JBoss 7 中部署 hibernate 应用程序时,出现错误。

javax.naming.NameNotFoundException: Name 'Manager1Factory' not found in context ''

引发此异常的代码行看起来像

    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>

我不确定为什么收到此错误 一样- 当我检查 JBoss 控制台时,我看到名称 Manager1Factory 显示在 JNDI 绑定下,因此看起来 EntityManagerFactory 正在创建,但没有被注入到我的类中?有什么想法为什么会发生这种情况吗?谢谢!

I get the error

javax.naming.NameNotFoundException: Name 'Manager1Factory' not found in context ''

when I try to deploy my hibernate app in JBoss 7. The line of code that is throwing this exception looks like

    entityManagerFactory = (EntityManagerFactory)ctx.lookup("java:/Manager1Factory");
EntityManager entityManager = entityManagerFactory.createEntityManager();

I have the JNDI name defined in persistence.xml like

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

I'm not sure why I'm receiving this error - when I check the JBoss console I see the name Manager1Factory shows up under JNDI bindings, so it seems like the EntityManagerFactory is being created but it is not being injected into my class? Any ideas why this is happening? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过期情话 2024-12-12 13:57:54

尝试使用

<property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/Manager1Factory"/>

and

java:jboss/Manager1Factory

Try with

<property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/Manager1Factory"/>

and

java:jboss/Manager1Factory
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文