与 tomcat 的接缝“entityManager 为空”

发布于 2024-12-08 13:56:26 字数 6504 浏览 0 评论 0原文

我在使用tomcat部署seam时遇到问题。我收到此错误:

Caused by: java.lang.IllegalStateException: entityManager is null
    at org.jboss.seam.framework.EntityQuery.validate(EntityQuery.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
    at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)

.......................................

这是我的详细信息。我遵循了 jboss seam jpa 示例中的所有详细信息:

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence 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" 
             version="1.0">
   <persistence-unit name="bookingDatabase">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <non-jta-data-source>java:comp/env/jdbc/TestDB</non-jta-data-source>
      <properties>
         <property name="hibernate.hbm2ddl.auto" value="validate"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
         <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
         
         
      </properties>
   </persistence-unit>
</persistence>

这是我的 component.xml。我认为没有问题。

Components.xml

<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://jboss.com/products/seam/components"
            xmlns:core="http://jboss.com/products/seam/core"
            xmlns:persistence="http://jboss.com/products/seam/persistence"
            xmlns:drools="http://jboss.com/products/seam/drools"
            xmlns:bpm="http://jboss.com/products/seam/bpm"
            xmlns:security="http://jboss.com/products/seam/security"
            xmlns:mail="http://jboss.com/products/seam/mail"
            xmlns:web="http://jboss.com/products/seam/web"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:cache="http://jboss.com/products/seam/cache"
            xmlns:async="http://jboss.com/products/seam/async"
            xmlns:transaction="http://jboss.com/products/seam/transaction"
            
            xsi:schemaLocation=
                    "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.2.xsd
                 http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.2.xsd
                 http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.2.xsd
                 http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.2.xsd
                 http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.2.xsd
                 http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.2.xsd
                 http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.2.xsd
                 http://jboss.com/products/seam/cache http://jboss.com/products/seam/cache-2.2.xsd
                 http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.2.xsd
                 http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.2.xsd
                 http://jboss.com/products/seam/async http://jboss.com/products/seam/async-2.0.xsd ">

     
      
    <core:manager concurrent-request-timeout="500"
                  conversation-timeout="120000"
                  conversation-id-parameter="cid"
                  parent-conversation-id-parameter="pid"/>
                  
    <transaction:entity-transaction entity-manager="#{em}"/>
                  
    <persistence:entity-manager-factory name="bookingDatabase"/>
    
    <persistence:managed-persistence-context name="em"
                               auto-create="true" 
                    entity-manager-factory="#{bookingDatabase}"/>
                    
    <security:identity authenticate-method="#{authenticator.authenticate}"/>  
    
    <async:quartz-dispatcher/>
    
    <cache:eh-cache-provider name="cacheProvider" auto-create="true"/>
    


    <!-- Make sure this URL pattern is the same as that used by the Faces Servlet -->
    <web:hot-deploy-filter url-pattern="*.seam"/>

    <drools:rule-base name="securityRules">
        <drools:rule-files>
            <value>/security.drl</value>
        </drools:rule-files>
    </drools:rule-base>

    <security:rule-based-permission-resolver security-rules="#{securityRules}"/>

    <security:jpa-identity-store
            user-class="org.domain.simpopanpa.entity.UserAccount"
            role-class="org.domain.simpopanpa.entity.UserRole"/>

    <security:jpa-permission-store
            user-permission-class="org.domain.simpopanpa.entity.UserPermission"/>



    <event type="org.jboss.seam.security.notLoggedIn">
        <action execute="#{redirect.captureCurrentView}"/>
    </event>
    <event type="org.jboss.seam.security.loginSuccessful">
        <action execute="#{redirect.returnToCapturedView}"/>
    </event>

    <mail:mail-session host="localhost" port="25"/>

    


   
</components>

我已经添加了 context.xml 文件,如某些论坛中所述。 context.xml

<Context path="/someName" docBase="someName"
        debug="5" reloadable="true" crossContext="true">

    <Resource auth="Container"
      name="jdbc/TestDB"
      type="javax.sql.DataSource"
      driverClassName="oracle.jdbc.OracleDriver"
      url="jdbc:oracle:thin:@127.0.0.1:1521:db11g"
      username="user"
      password="pass"
      maxActive="100"
      maxIdle="30"
      maxWait="10000"/>
 
</Context>

我使用 tomcat 7 和 jboss seam 2.2.1

I have a problem when deploying seam with tomcat. I get this error :

Caused by: java.lang.IllegalStateException: entityManager is null
    at org.jboss.seam.framework.EntityQuery.validate(EntityQuery.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
    at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)

.......................................

Here are my details. I have followed all the details from jboss seam jpa example :

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence 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" 
             version="1.0">
   <persistence-unit name="bookingDatabase">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <non-jta-data-source>java:comp/env/jdbc/TestDB</non-jta-data-source>
      <properties>
         <property name="hibernate.hbm2ddl.auto" value="validate"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
         <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
         
         
      </properties>
   </persistence-unit>
</persistence>

This is my component.xml. I think there is no problem with it.

components.xml

<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://jboss.com/products/seam/components"
            xmlns:core="http://jboss.com/products/seam/core"
            xmlns:persistence="http://jboss.com/products/seam/persistence"
            xmlns:drools="http://jboss.com/products/seam/drools"
            xmlns:bpm="http://jboss.com/products/seam/bpm"
            xmlns:security="http://jboss.com/products/seam/security"
            xmlns:mail="http://jboss.com/products/seam/mail"
            xmlns:web="http://jboss.com/products/seam/web"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:cache="http://jboss.com/products/seam/cache"
            xmlns:async="http://jboss.com/products/seam/async"
            xmlns:transaction="http://jboss.com/products/seam/transaction"
            
            xsi:schemaLocation=
                    "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.2.xsd
                 http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.2.xsd
                 http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.2.xsd
                 http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.2.xsd
                 http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.2.xsd
                 http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.2.xsd
                 http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.2.xsd
                 http://jboss.com/products/seam/cache http://jboss.com/products/seam/cache-2.2.xsd
                 http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.2.xsd
                 http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.2.xsd
                 http://jboss.com/products/seam/async http://jboss.com/products/seam/async-2.0.xsd ">

     
      
    <core:manager concurrent-request-timeout="500"
                  conversation-timeout="120000"
                  conversation-id-parameter="cid"
                  parent-conversation-id-parameter="pid"/>
                  
    <transaction:entity-transaction entity-manager="#{em}"/>
                  
    <persistence:entity-manager-factory name="bookingDatabase"/>
    
    <persistence:managed-persistence-context name="em"
                               auto-create="true" 
                    entity-manager-factory="#{bookingDatabase}"/>
                    
    <security:identity authenticate-method="#{authenticator.authenticate}"/>  
    
    <async:quartz-dispatcher/>
    
    <cache:eh-cache-provider name="cacheProvider" auto-create="true"/>
    


    <!-- Make sure this URL pattern is the same as that used by the Faces Servlet -->
    <web:hot-deploy-filter url-pattern="*.seam"/>

    <drools:rule-base name="securityRules">
        <drools:rule-files>
            <value>/security.drl</value>
        </drools:rule-files>
    </drools:rule-base>

    <security:rule-based-permission-resolver security-rules="#{securityRules}"/>

    <security:jpa-identity-store
            user-class="org.domain.simpopanpa.entity.UserAccount"
            role-class="org.domain.simpopanpa.entity.UserRole"/>

    <security:jpa-permission-store
            user-permission-class="org.domain.simpopanpa.entity.UserPermission"/>



    <event type="org.jboss.seam.security.notLoggedIn">
        <action execute="#{redirect.captureCurrentView}"/>
    </event>
    <event type="org.jboss.seam.security.loginSuccessful">
        <action execute="#{redirect.returnToCapturedView}"/>
    </event>

    <mail:mail-session host="localhost" port="25"/>

    


   
</components>

I have added the context.xml file as described in some forums.
context.xml

<Context path="/someName" docBase="someName"
        debug="5" reloadable="true" crossContext="true">

    <Resource auth="Container"
      name="jdbc/TestDB"
      type="javax.sql.DataSource"
      driverClassName="oracle.jdbc.OracleDriver"
      url="jdbc:oracle:thin:@127.0.0.1:1521:db11g"
      username="user"
      password="pass"
      maxActive="100"
      maxIdle="30"
      maxWait="10000"/>
 
</Context>

I use tomcat 7 and jboss seam 2.2.1

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

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

发布评论

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

评论(1

谁人与我共长歌 2024-12-15 13:56:26

您将持久性上下文命名为“em”。实体查询默认尝试通过“entitymanager”获取它。因此,要么更改 Components.xml 中的名称,要么必须调用entityquery.setPersistenceContextName("em")。

You named the persistence context 'em'. The entityquery is per default trying to fetch it by 'entitymanager'. So either change the name in your components.xml or you have to call entityquery.setPersistenceContextName("em").

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