0 Replies Latest reply on Oct 30, 2010 2:26 PM by Matthew Edor

    Exception creating entitymanager with hibernate filters enabled

    Matthew Edor Newbie
      I have a program that wasn't using hibernate filters. I decided to modify it for use with filters. However, any time the filters are enabled, I get a nullpointerexception when trying to create an entityManager.
      The filter class is as follows:


      `
      @FilterDefs(
      value={@FilterDef(name="depotSupervisorIP",
                                                      parameters={@ParamDef(name="userId", type="String"),
                                                                              @ParamDef(name="userClasses", type="String")}),
                                              @FilterDef(name="depotSupervisorTickets",
                                                      parameters={@ParamDef(name="userId", type="String"),
                                                                              @ParamDef(name="userClasses", type="String")}),
                                              @FilterDef(name="depotSupervisorDO5s",
                                                      parameters={@ParamDef(name="userId", type="String")}),
                                              @FilterDef(name="depotManagerIP",
                                                      parameters={@ParamDef(name="userId", type="String")}),
                                              @FilterDef(name="depotManagerTickets",
                                                      parameters={@ParamDef(name="userId", type="String")}),
                                              @FilterDef(name="depotTickets",
                                                      parameters={@ParamDef(name="userClasses", type="String")}),
                                              @FilterDef(name="depotIP",
                                                      parameters={@ParamDef(name="userClasses", type="String")}),
                                              @FilterDef(name="hqTickets",
                                                      parameters={@ParamDef(name="userClasses", type="String")}),
                                              @FilterDef(name="hqIP",
                                                      parameters={@ParamDef(name="userClasses", type="String")}),
                                              @FilterDef(name="marketerFilter",
                                                      parameters={@ParamDef(name="userId", type="String")})
      })

      package com.mattae.billing.domain;

      import org.hibernate.annotations.FilterDef;
      import org.hibernate.annotations.FilterDefs;
      import org.hibernate.annotations.ParamDef;`
      `
      The component.xml file is:
      `
      <?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:bpm="http://jboss.com/products/seam/bpm"
                              xmlns:security="http://jboss.com/products/seam/security"
                              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                              xmlns:drools="http://jboss.com/products/seam/drools"
                              xmlns:web="http://jboss.com/products/seam/web"
                              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/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/components
                                      http://jboss.com/products/seam/components-2.2.xsd">
              <core:manager concurrent-request-timeout="1000"
                                              conversation-id-parameter="cid"
                                              conversation-timeout="120000"
                                              parent-conversation-id-parameter="pid"/>
              <web:context-filter url-pattern ="/reports/*"/>
              <persistence:entity-manager-factory name="billingEntityManagerFactory"
                                              persistence-unit-name="billing"/>
              <persistence:filter name="depotSupervisorIP" enabled="#{identity.hasRole('DEPOT') and !identity.hasRole('USERS')}">
                      <persistence:name>depotSupervisorIP</persistence:name>
                      <persistence:parameters>
                              <key>userId</key>
                              <value>#{user.id}</value>
                              <key>userClasses</key>
                              <value>#{login.classes}</value>
                      </persistence:parameters>
              </persistence:filter>
              <persistence:filter name="depotSupervisorTickets" enabled="#{identity.hasRole('DEPOT') and !identity.hasRole('USERS')}">
                      <persistence:name>depotSupervisorTickets</persistence:name>
                      <persistence:parameters>
                              <key>userId</key>
                              <value>#{user.id}</value>
                              <key>userClasses</key>
                              <value>#{login.classes}</value>
                      </persistence:parameters>
              </persistence:filter>
              <persistence:filter name="depotSupervisorDO5s" enabled="#{identity.hasRole('DEPOT') and !identity.hasRole('USERS')}">
                      <persistence:name>depotSupervisorDO5s</persistence:name>
                      <persistence:parameters>
                              <key>userId</key>
                              <value>#{user.id}</value>
                      </persistence:parameters>
              </persistence:filter>
              <persistence:filter name="depotManagerIP" enabled="#{identity.hasRole('DEPOT') and identity.hasRole('USERS')}">
                      <persistence:name>depotManagerIP</persistence:name>
                      <persistence:parameters>
                              <key>userId</key>
                              <value>#{user.id}</value>
                      </persistence:parameters>
              </persistence:filter>
              <persistence:filter name="depotManagerTicket" enabled="#{identity.hasRole('DEPOT') and identity.hasRole('USERS')}">
                      <persistence:name>depotManagerTickets</persistence:name>
                      <persistence:parameters>
                              <key>userId</key>
                              <value>#{user.id}</value>
                      </persistence:parameters>
              </persistence:filter>
              <persistence:filter name="depotIP" enabled="#{identity.hasRole('DEPOT')}">
                      <persistence:name>depotIP</persistence:name>
                      <persistence:parameters>
                              <key>userId</key>
                              <value>#{user.id}</value>
                      </persistence:parameters>
              </persistence:filter>
              <persistence:filter name="depotTickets" enabled="#{identity.hasRole('DEPOT')}">
                      <persistence:name>depotTickets</persistence:name>
                      <persistence:parameters>
                              <key>userId</key>
                              <value>#{user.id}</value>
                      </persistence:parameters>
              </persistence:filter>
              <persistence:filter name="marketerFilter" enabled="#{!((identity.hasRole('MANAGER') and identity.hasRole('DEPOT')) or identity.hasRole('REPORTS'))}">
                      <persistence:name>marketerFilter</persistence:name>
                      <persistence:parameters>
                              <key>userId</key>
                              <value>#{user.id}</value>
                      </persistence:parameters>
              </persistence:filter>
              <persistence:filter name="hqIP" enabled="#{identity.hasRole('HQ')}">
                      <persistence:name>hqIP</persistence:name>
                      <persistence:parameters>
                              <key>userId</key>
                              <value>#{user.id}</value>
                      </persistence:parameters>
              </persistence:filter>
              <persistence:filter name="hqTickets" enabled="#{identity.hasRole('HQ')}">
                      <persistence:name>hqTickets</persistence:name>
                      <persistence:parameters>
                              <key>userId</key>
                              <value>#{user.id}</value>
                      </persistence:parameters>
              </persistence:filter>
              <persistence:managed-persistence-context auto-create="true"
                                              entity-manager-factory="#{billingEntityManagerFactory}"
                                              name="entityManager"
                                              persistence-unit-jndi-name="java:/billingEMF">
                      <persistence:filters>
                              <value>#{depotSupervisorIP}</value>
                              <value>#{depotSupervisorTickets}</value>
                              <value>#{depotSupervisorDO5s}</value>
                              <value>#{depotManagerIP}</value>
                              <value>#{depotManagerTickets}</value>
                              <value>#{hqIP}</value>
                              <value>#{hqTickets}</value>
                              <value>#{depotIP}</value>
                              <value>#{depotTickets}</value>
                              <value>#{marketersFilter}</value>
                      </persistence:filters>
              </persistence:managed-persistence-context>
              <drools:rule-base name ="securityRules">
                      <drools:rule-files>
                              <value>/security.drl</value>
                      </drools:rule-files>
              </drools:rule-base>
              <security:identity/>
              <security:jpa-identity-store user-class ="com.mattae.billing.domain.User" role-class ="com.mattae.billing.domain.Role"/>
      </components>
      `
      and the error:
      `
      2010-10-30 14:43:32,304 WARN  [org.jboss.seam.security.jaas.SeamLoginModule] (http-localhost%2F127.0.0.1-8080-1) Error invoking login method
      2010-10-30 14:43:32,305 DEBUG [org.jboss.seam.security.Identity] (http-localhost%2F127.0.0.1-8080-1) Login failed for: mattae
      javax.security.auth.login.LoginException
              at org.jboss.seam.security.jaas.SeamLoginModule.login(SeamLoginModule.java:143)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:616)
              at javax.security.auth.login.LoginContext.invoke(LoginContext.java:784)
              at javax.security.auth.login.LoginContext.access$000(LoginContext.java:203)
              at javax.security.auth.login.LoginContext$5.run(LoginContext.java:721)
              at javax.security.auth.login.LoginContext$5.run(LoginContext.java:719)
              at java.security.AccessController.doPrivileged(Native Method)
              at javax.security.auth.login.LoginContext.invokeCreatorPriv(LoginContext.java:718)
              at javax.security.auth.login.LoginContext.login(LoginContext.java:590)
              at org.jboss.seam.security.Identity.authenticate(Identity.java:344)
              at org.jboss.seam.security.Identity.authenticate(Identity.java:332)
              at org.jboss.seam.security.Identity.login(Identity.java:259)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:616)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348)
              at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
              at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
              at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
              at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
              at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
              at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
              at javax.faces.component.UICommand.broadcast(UICommand.java:387)
              at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:329)
              at org.ajax4jsf.component.AjaxViewRoot.broadcastEventsForPhase(AjaxViewRoot.java:304)
              at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:261)
              at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:474)
              at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
              at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)
              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
              at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
              at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
              at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
              at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
              at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
              at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
              at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
              at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
              at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
              at java.lang.Thread.run(Thread.java:636)
      Caused by: java.lang.NullPointerException
              at org.jboss.seam.persistence.ManagedPersistenceContext.initEntityManager(ManagedPersistenceContext.java:86)
              at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:108)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:616)
              at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
              at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
              at org.jboss.seam.Component.callComponentMethod(Component.java:2275)
              at org.jboss.seam.Component.unwrap(Component.java:2301)
              at org.jboss.seam.Component.getInstance(Component.java:2044)
              at org.jboss.seam.Component.getInstance(Component.java:1986)
              at org.jboss.seam.Component.getInstance(Component.java:1980)
              at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
              at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
              at org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:148)
              at org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:51)
              at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
              at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
              at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
              at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
              at org.jboss.seam.core.Expressions$1.getValue(Expressions.java:112)
              at org.jboss.seam.security.management.JpaIdentityStore.lookupEntityManager(JpaIdentityStore.java:1051)
              at org.jboss.seam.security.management.JpaIdentityStore.lookupUser(JpaIdentityStore.java:860)
              at org.jboss.seam.security.management.JpaIdentityStore.authenticate(JpaIdentityStore.java:806)
              at org.jboss.seam.security.management.IdentityManager.authenticate(IdentityManager.java:271)
              at org.jboss.seam.security.jaas.SeamLoginModule.login(SeamLoginModule.java:128)
              ... 77 more
      `
      The exception disappears when the <persistence:filters> block is removed.
      I seem to be confused, as I followed the examples given on how to user hibernate filters with seam. I've tried it with both Seam 2.2.0 GA and Seam 2.2.1 CR and still get the same error. Your assistance will be highly appreciated.
      Thanks!!