3 Replies Latest reply on Jun 3, 2009 9:32 PM by jkronegg

    Eclipselink persistenceProvider in Seam.

    jcharnet

      Hello.
      My application already uses Eclipselink as the persistence provider. We are now putting Seam in our application, especially to use Seam security (authentication and authorization).
      I tried to configure the persistence provider in seam, but I'm getting the following castClassException



      java.lang.ClassCastException: org.eclipse.persistence.jpa.PersistenceProvider_$$_javassist_1 cannot be cast to org.jboss.seam.persistence.PersistenceProvider
           at org.jboss.seam.persistence.PersistenceProvider.instance(PersistenceProvider.java:126)
           at org.jboss.seam.persistence.ManagedPersistenceContext.initEntityManager(ManagedPersistenceContext.java:79)
           at org.jboss.seam.persistence.ManagedPersistenceContext.getEntityManager(ManagedPersistenceContext.java:107)
           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.util.Reflections.invokeAndWrap(Reflections.java:144)
           at org.jboss.seam.Component.callComponentMethod(Component.java:2211)
           at org.jboss.seam.Component.unwrap(Component.java:2237)
           at org.jboss.seam.Component.getInstance(Component.java:2004)
           at org.jboss.seam.Component.getInstance(Component.java:1950)
           at org.jboss.seam.Component.getInstance(Component.java:1944)
           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:166)
           at org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:53)
           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:987)
           at org.jboss.seam.security.management.JpaIdentityStore.lookupUser(JpaIdentityStore.java:796)
           at org.jboss.seam.security.management.JpaIdentityStore.authenticate(JpaIdentityStore.java:760)
           at org.jboss.seam.security.management.IdentityManager.authenticate(IdentityManager.java:271)
           at org.jboss.seam.security.jaas.SeamLoginModule.login(SeamLoginModule.java:126)
           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 javax.security.auth.login.LoginContext.invoke(LoginContext.java:769)
           at javax.security.auth.login.LoginContext.access$000(LoginContext.java:186)
           at javax.security.auth.login.LoginContext$5.run(LoginContext.java:706)
           at java.security.AccessController.doPrivileged(Native Method)
           at javax.security.auth.login.LoginContext.invokeCreatorPriv(LoginContext.java:703)
           at javax.security.auth.login.LoginContext.login(LoginContext.java:575)
           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:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
           at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:342)
           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:321)
           at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
           at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
           at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
           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.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:532)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
           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.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:619)
      



      Here are my configurations files:
      components.xml
      ------------



      <?xml version="1.0"?>
      <components xmlns="http://jboss.com/products/seam/components"
           xmlns:persistence="http://jboss.com/products/seam/persistence"
           xmlns:security="http://jboss.com/products/seam/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd                  http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd                  http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd                  http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd                  http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd                  http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd                  http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
           <security:identity />
           <security:jpa-identity-store
                role-class="br.com.softcomex.model.base.entity.SwGrupo" user-class="br.com.softcomex.model.base.entity.SwUsuario" />
           <persistence:entity-manager-factory
                installed="false" name="NvsPU" persistence-unit-name="NvsPU" />
           <persistence:managed-persistence-context
                auto-create="true" entity-manager-factory="#{NvsPU}" name="entityManager"
                persistence-unit-jndi-name="java:/jdbc/SfwBaseDS" />
           <component class="org.eclipse.persistence.jpa.PersistenceProvider"
                name="org.jboss.seam.persistence.persistenceProvider" />
      </components>




      ------------


      persistence.xml
      ------------



      <?xml version="1.0" encoding="windows-1252" ?>
      <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" xmlns="http://java.sun.com/xml/ns/persistence">
           <persistence-unit name="NvsPU" transaction-type="JTA">
                <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
                <jta-data-source>java:/jdbc/SfwBaseDS</jta-data-source>
                <properties>
                     <property name="eclipselink.target-server" value="JBoss" />
                     <property name="eclipselink.logging.level" value="FINE"/>
                     <property name="eclipselink.cache.type.default" value="NONE"/>
                     <property name="jboss.entity.manager.factory.jndi.name" value="java:/jdbc/SfwBaseDS"/>
                </properties>
           </persistence-unit>
      </persistence>




      ------------


      Any idea what I'm doing wrong ?


      Thanks a lot.
      John


        • 1. Re: Eclipselink persistenceProvider in Seam.
          jkronegg

          Making Seam to work with another JPA persistence provider than Hibernate is not out-of-the-box.


          You should look at the Knowledge Base article Using OpenJPA as persistence provider instead of Hibernate which do the job for the OpenJPA persistence provider.


          Also have a look to the JIRA issues for other JPA providers: JIRA issues for JPA providers.

          • 2. Re: Eclipselink persistenceProvider in Seam.
            jcharnet

            Thanks for the reponse Julien.
            I was able to configure eclipselink in seam, I had to overwrite hibernatePersistenceProvider with Seams default persistenceProvider.


            Instead of putting the eclipselink as the persistence provider in components.xml I put the following:



            <component class="org.jboss.seam.persistence.PersistenceProvider"
                      name="org.jboss.seam.persistence.persistenceProvider" 
                      scope="stateless" />



            This seems to have done it, but now I'm facing another problem. When the JpaIdentityStore is called (to login a user), it builds the query with the full qualified name User class:



            select u from br.com.softcomex.model.base.entity.SwUser u where username = :username



            Hibernate seems to parse this jpql correctly, and it generates the following query:



            select u from SwUser u where username = :username



            Which can be executed by the entityManager.
            Eclispse link (not sure why), does not change the fully qualified User class. So it still has the package in the from clause.
            This causes a token error when the entityManager tries to execute the query.


            Any ideas why this happens ?


            Thanks again.


            John










            • 3. Re: Eclipselink persistenceProvider in Seam.
              jkronegg

              I'm sorry John, I have no idea. Maybe there is a parameter which allows to add/remove the package name?