шов с котом "entityManager is null" - PullRequest
0 голосов
/ 04 октября 2011

У меня проблема при развертывании шва с помощью tomcat. Я получаю эту ошибку:

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.

1 Ответ

0 голосов
/ 06 октября 2011

Вы назвали контекст постоянства em. По умолчанию entityquery пытается получить его с помощью entitymanager. Так что либо измените имя в вашем component.xml, либо вам нужно вызвать entityquery.setPersistenceContextName ("em").

...