7 Replies Latest reply on Jan 21, 2011 11:57 PM by richard yang

    Not able to use seam persistence

    Murali Mohan Rath Newbie
      I have a web app running in jetty fine with some code for creating persistence context manually. I added few lines of code to use seam-persistence.

      1. My beans.xml looks as below

      <beans xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:s="urn:java:ee"
         xmlns:t="urn:java:org.jboss.seam.persistence.transaction"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
         http://docs.jboss.org/cdi/beans_1_0.xsd">
          <interceptors>
              <class>org.jboss.seam.persistence.transaction.TransactionInterceptor</class>
          </interceptors>

          <t:SeSynchronizations>
              <s:modifies/>
          </t:SeSynchronizations>

          <t:EntityTransaction>
              <s:modifies />
          </t:EntityTransaction>
      </beans>



      2. Added the following to POM


              <dependency>
                  <groupId>org.jboss.seam.persistence</groupId>
                  <artifactId>seam-persistence</artifactId>
                  <version>3.0.0.Beta2</version>
              </dependency>
              <dependency>
                  <groupId>org.jboss.seam.config</groupId>
                  <artifactId>seam-config-xml</artifactId>
                  <version>3.0.0.Beta2</version>
                  <scope>runtime</scope>
              </dependency>


      3. created the following code. Not sure if this is correct


      public class PersistenceContextProvider {

          @SeamManaged
          @Produces
          @PersistenceUnit
          @ConversationScoped
          EntityManagerFactory producerField;

      }


      4. injecting em as below

          @Inject
          private EntityManager entityManager;




      I am getting the following exception

      Jan 17, 2011 9:32:52 PM org.jboss.weld.bootstrap.WeldBootstrap <clinit>
      INFO: WELD-000900 1.0.1 (Final)
      2011-01-17 21:32:52.405:INFO::No Transaction manager found - if your webapp requires one, please configure one.
      Jan 17, 2011 9:32:53 PM org.jboss.weld.environment.servlet.deployment.AbstractScanner handle
      SEVERE: Error loading org/jboss/seam/persistence/transaction/EjbSynchronizations.class
      java.lang.NoClassDefFoundError: javax/ejb/SessionSynchronization
           at java.lang.ClassLoader.defineClass1(Native Method)
           at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
           at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
           at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
           at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
           at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
           at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
           at java.security.AccessController.doPrivileged(Native Method)
           at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
           at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:392)
           at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:363)
           at org.jboss.weld.environment.servlet.deployment.AbstractScanner.handle(AbstractScanner.java:53)
           at org.jboss.weld.environment.servlet.deployment.URLScanner.handleArchiveByFile(URLScanner.java:149)
           at org.jboss.weld.environment.servlet.deployment.URLScanner.handle(URLScanner.java:126)
           at org.jboss.weld.environment.servlet.deployment.URLScanner.scanResources(URLScanner.java:107)
           at org.jboss.weld.environment.servlet.deployment.WebAppBeanDeploymentArchive.scan(WebAppBeanDeploymentArchive.java:80)
           at org.jboss.weld.environment.servlet.deployment.WebAppBeanDeploymentArchive.<init>(WebAppBeanDeploymentArchive.java:59)
           at org.jboss.weld.environment.servlet.deployment.ServletDeployment.<init>(ServletDeployment.java:22)
           at org.jboss.weld.environment.servlet.Listener.contextInitialized(Listener.java:109)
           at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:549)
           at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
           at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1282)
           at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518)
           at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499)
           at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:115)
           at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
           at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
           at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
           at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
           at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
           at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
           at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
           at org.mortbay.jetty.Server.doStart(Server.java:224)
           at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
           at org.mortbay.jetty.plugin.Jetty6PluginServer.start(Jetty6PluginServer.java:132)
           at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:454)
           at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:396)
           at org.mortbay.jetty.plugin.AbstractJettyRunMojo.execute(AbstractJettyRunMojo.java:210)
           at org.mortbay.jetty.plugin.Jetty6RunMojo.execute(Jetty6RunMojo.java:184)
           at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
           at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:195)
           at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
           at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:140)
           at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
           at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
           at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
           at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
           at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:316)
           at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:153)
           at org.apache.maven.cli.MavenCli.execute(MavenCli.java:451)
           at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:188)
           at org.apache.maven.cli.MavenCli.main(MavenCli.java:134)
           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.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
           at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
           at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
           at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
      Caused by: java.lang.ClassNotFoundException: javax.ejb.SessionSynchronization
           at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
           at java.security.AccessController.doPrivileged(Native Method)
           at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
           at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:392)
           at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:363)
           ... 60 more
      Jan 17, 2011 9:32:53 PM org.jboss.weld.bootstrap.WeldBootstrap startContainer
      INFO: WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
      Jan 17, 2011 9:32:53 PM org.jboss.seam.solder.core.CoreExtension beforeBeanDiscovery
      INFO: Seam Solder 3.0.0.Beta1 (build id: 20101220-2046)
      Jan 17, 2011 9:32:53 PM org.jboss.seam.config.xml.bootstrap.XmlConfigExtension beforeBeanDiscovery
      INFO: Seam Config XML provider starting...
      Jan 17, 2011 9:32:53 PM org.jboss.seam.config.xml.bootstrap.XmlConfigExtension getDocumentProviders
      INFO: Loading XmlDocumentProvider: org.jboss.seam.config.xml.bootstrap.ResourceLoaderXmlDocumentProvider
      Jan 17, 2011 9:32:53 PM org.jboss.seam.config.xml.bootstrap.XmlConfigExtension beforeBeanDiscovery
      INFO: Reading XML file: file:/home/murali/workspace/ct/ct-web/target/classes/META-INF/beans.xml
      Jan 17, 2011 9:32:53 PM org.jboss.seam.config.xml.bootstrap.XmlConfigExtension beforeBeanDiscovery
      INFO: Adding XML Defined Bean: org.jboss.seam.persistence.transaction.SeSynchronizations
      Jan 17, 2011 9:32:53 PM org.jboss.seam.config.xml.bootstrap.XmlConfigExtension beforeBeanDiscovery
      INFO: Adding XML Defined Bean: org.jboss.seam.persistence.transaction.EntityTransaction
      Jan 17, 2011 9:32:53 PM org.jboss.weld.environment.servlet.Listener contextInitialized
      INFO: JSR-299 injection will not be available in Servlets, Filters etc. This facility is only available in Tomcat
      Jan 17, 2011 9:32:54 PM org.jboss.interceptor.model.InterceptionTypeRegistry <clinit>
      WARNING: Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled
      Jan 17, 2011 9:32:54 PM org.jboss.interceptor.model.InterceptionTypeRegistry <clinit>
      WARNING: Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled
      Jan 17, 2011 9:32:54 PM org.jboss.seam.solder.core.CoreExtension processAnnotatedType
      INFO: Preventing class org.jboss.seam.persistence.transaction.UTTransaction from being installed as bean due to @Veto annotation
      2011-01-17 21:32:54.364:WARN::Failed startup of context org.mortbay.jetty.plugin.Jetty6PluginWebAppContext@73d742a1{/ct-web,/home/murali/workspace/ct/ct-web/src/main/webapp}
      com.google.common.collect.ComputationException: java.lang.NoClassDefFoundError: javax/ejb/EJBContext
           at com.google.common.collect.MapMaker$StrategyImpl.compute(MapMaker.java:602)
           at com.google.common.collect.MapMaker$StrategyImpl.compute(MapMaker.java:462)
           at com.google.common.collect.CustomConcurrentHashMap$ComputingImpl.get(CustomConcurrentHashMap.java:2045)
           at org.jboss.weld.resources.ClassTransformer.loadClass(ClassTransformer.java:164)
           at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:61)
           at org.jboss.weld.bootstrap.BeanDeployer.addClasses(BeanDeployer.java:88)
           at org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:134)
           at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:377)
           at org.jboss.weld.environment.servlet.Listener.contextInitialized(Listener.java:171)
           at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:549)
           at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
           at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1282)
           at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518)
           at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499)
           at org.mortbay.jetty.plugin.Jetty6PluginWebAppContext.doStart(Jetty6PluginWebAppContext.java:115)
           at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
           at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
           at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
           at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
           at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
           at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
           at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
           at org.mortbay.jetty.Server.doStart(Server.java:224)
           at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
           at org.mortbay.jetty.plugin.Jetty6PluginServer.start(Jetty6PluginServer.java:132)
           at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:454)
           at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:396)
           at org.mortbay.jetty.plugin.AbstractJettyRunMojo.execute(AbstractJettyRunMojo.java:210)
           at org.mortbay.jetty.plugin.Jetty6RunMojo.execute(Jetty6RunMojo.java:184)
           at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
           at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:195)
           at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
           at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:140)
           at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
           at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
           at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
           at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
           at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:316)
           at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:153)
           at org.apache.maven.cli.MavenCli.execute(MavenCli.java:451)
           at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:188)
           at org.apache.maven.cli.MavenCli.main(MavenCli.java:134)
           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.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
           at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
           at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
           at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
      2011-01-17 21:32:54.398:INFO::Started SelectChannelConnector@0.0.0.0:9090
      [INFO] Started Jetty Server
      [INFO] Starting scanner at interval of 3 seconds.



        • 1. Re: Not able to use seam persistence
          Jason Porter Master

          Hopefully Shane can comment on this, but it's looking to me like this is a problem because you're in Jetty 6/7 and you don't have the EJB APIs, probably because you're using @PersistenceContext.  I haven't tried running outside of a Java EE 6 container, so I'm honestly not sure if I'm telling you correctly or not.  Try adding the jars, or look for an embedded EJB3.1 container and give that a shot.

          • 2. Re: Not able to use seam persistence
            Shane Bryzak Master

            What Jason says sounds right, however I'm a Jetty noob so probably Stuart would be the best person to answer this question.  I'll see if he can take a quick look at this.

            • 3. Re: Not able to use seam persistence
              Stuart Douglas Master

              What version of weld are you running? Older versions of weld would die if they encountered a NoClassDefFoundException while scanning.

              • 4. Re: Not able to use seam persistence
                richard yang Newbie

                I have another issue. We run jboss AS 6 with weld. Now I am adding seam 3 persistence module (SMPC) as we see the limitation of Entended persistence context type in SFSB.
                I also heard that with seam 3 persistence module, we do not even have to use a EJB to have transaction, a simple annotaion @TransactionAttribute will do the trick. But I tried it out with 


                <interceptors>        <class>org.jboss.seam.persistence.transaction.TransactionInterceptor</class></interceptors>



                turned on in beans.xml (beans.xml is under WEB-INF). But it does not seem to work. I got no transaction error when I create an entity. But if I annotation the bean with @Stateless or @Stateful, along with @TransactionAttribute, then the entity can be created into database.


                Anybody in this forum can enlighten me? Is that still true that we do not need ejb to use SMPC?

                • 5. Re: Not able to use seam persistence
                  Stuart Douglas Master

                  Can you post some more details?
                  - The code for the class that you are annotating
                  - Where is this class (WEB-INF/classes?)
                  - Which container are you using?

                  • 6. Re: Not able to use seam persistence
                    richard yang Newbie
                    See the code snippet:


                    @TransactionAttribute
                    public class TestServiceImpl implements TestService {

                        @Inject
                        private TestDAO testDAO;

                        @Inject
                        @TestDBRepo
                        @PersistenceContext
                        private EntityManager testEm;

                        @Inject
                        @Updated
                       

                    `Event<TestUser> userEvent;`



                        @Inject
                        private Logger log;

                        public TestServiceImpl() {

                        }

                    //producer class
                    public class TestDBRepoProducer {
                        @TestDBRepo
                        @SeamManaged
                        @ConversationScoped
                        @Produces
                        @PersistenceUnit(unitName = "testPU")
                        EntityManagerFactory emf;
                    }


                        @PostConstruct
                        private void setEm() {
                            testDAO.setEm(testEm);
                        }

                        @Override
                        public TestUser getByUserById(int id) {
                            return testDAO.findById(id);
                        }

                    }
                    • 7. Re: Not able to use seam persistence
                      richard yang Newbie

                      Also, I run the webapp under jboss AS 6 Final.


                      I also tried seam 3 security module (alpha1). It did not work with the rest of the modulesv(got deployment error) as it still depends on weld-extension while other modules depend on solder.