2011-10-04 22 views
0

我在使用tomcat部署接縫時遇到問題。我得到這個錯誤:與tomcat的接縫「entityManager爲空」

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

如果任何人都可以給我一個提示。

Thx。

回答

0

您將持久化上下文命名爲'em'。 entityquery默認試圖通過'entitymanager'獲取它。因此,要麼在components.xml中更改名稱,要麼必須調用entityquery.setPersistenceContextName(「em」)。