2 Replies Latest reply on Feb 19, 2013 6:28 AM by Piero Uniti

    ejb transactionEJBs, Web services, persistence problem

    Klearchos Klearchou Newbie
      Hello to all,

      I use jboss-seam-2.0.3.CR1 and jboss-as-4.2.2.GA exactly as in the
      Seam in action.

      I created a simple application that works fine under the browser.
      Now I am trying to make the same under the web services.

      I have added the xml file to the deployable file according to the
      reference manual.

      I instantiate the required components through the Component.getInstance

      When the time comes in order to call a method from this instantiated object
      that includes changes to the DB I receive the following exception:



      18:37:46 INFO [STDOUT] Hibernate:
          call identity()
      18:37:46 ERROR [STDERR] java.lang.IllegalStateException: Transaction begin not d
      etected, try installing transaction:ejb-transaction in components.xml
      18:37:46 ERROR [STDERR]         at org.jboss.seam.transaction.SeSynchronizations
      .registerSynchronization(SeSynchronizations.java:57)
      18:37:46 ERROR [STDERR]         at org.jboss.seam.transaction.UTTransaction.regi
      sterSynchronization(UTTransaction.java:92)
      18:37:46 ERROR [STDERR]         at org.jboss.seam.async.AbstractDispatcher.sched
      uleTransactionSuccessEvent(AbstractDispatcher.java:90)
      18:37:46 ERROR [STDERR]         at sun.reflect.NativeMethodAccessorImpl.invoke0(
      Native Method)
      18:37:46 ERROR [STDERR]         at sun.reflect.NativeMethodAccessorImpl.invoke(N
      ativeMethodAccessorImpl.java:39)
      18:37:46 ERROR [STDERR]         at sun.reflect.DelegatingMethodAccessorImpl.invo
      ke(DelegatingMethodAccessorImpl.java:25)
      18:37:46 ERROR [STDERR]         at java.lang.reflect.Method.invoke(Method.java:5
      85)
      18:37:46 ERROR [STDERR]         at org.jboss.seam.util.Reflections.invoke(Reflec
      tions.java:21)
      18:37:46 ERROR [STDERR]         at org.jboss.seam.intercept.RootInvocationContex
      t.proceed(RootInvocationContext.java:31)
      18:37:46 ERROR [STDERR]         at org.jboss.seam.intercept.SeamInvocationContex
      t.proceed(SeamInvocationContext.java:56)
      18:37:46 ERROR [STDERR]         at org.jboss.seam.transaction.RollbackIntercepto
      r.aroundInvoke(RollbackInterceptor.java:31)
      18:37:46 ERROR [STDERR]         at org.jboss.seam.intercept.SeamInvocationContex
      t.proceed(SeamInvocationContext.java:68)
      18:37:46 ERROR [STDERR]         at org.jboss.seam.core.MethodContextInterceptor.
      aroundInvoke(MethodContextInterceptor.java:42)
      18:37:46 ERROR [STDERR]         at org.jboss.seam.intercept.SeamInvocationContex
      t.proceed(SeamInvocationContext.java:68)
      18:37:46 ERROR [STDERR]         at org.jboss.seam.intercept.RootInterceptor.invo
      ke(RootInterceptor.java:107)
      18:37:46 ERROR [STDERR]         at org.jboss.seam.intercept.JavaBeanInterceptor.
      interceptInvocation(JavaBeanInterceptor.java:166)
      18:37:46 ERROR [STDERR]         at org.jboss.seam.intercept.JavaBeanInterceptor.
      invoke(JavaBeanInterceptor.java:102)
      18:37:46 ERROR [STDERR]         at org.jboss.seam.async.ThreadPoolDispatcher_$$_
      javassist_3.scheduleTransactionSuccessEvent(ThreadPoolDispatcher_$$_javassist_3.
      java)
      18:37:46 ERROR [STDERR]         at org.jboss.seam.core.Events.raiseTransactionSu
      ccessEvent(Events.java:125)
      18:37:46 ERROR [STDERR]         at com.eurodyn.action.passportReader.RegisterPas
      sportAction.register(RegisterPassportAction.java:52)
      18:37:46 ERROR [STDERR]         at sun.reflect.NativeMethodAccessorImpl.invoke0(
      Native Method)
      18:37:46 ERROR [STDERR]         at sun.reflect.NativeMethodAccessorImpl.invoke(N
      ativeMethodAccessorImpl.java:39)


      If I try to insert the <transaction:ejb-transaction /> under the components.xml
      then the application will crash during the initialization of the components.xml


      I will list some of my application files.
      In case you required more information please let me know.

      persistence.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Persistence deployment descriptor for dev profile -->
      <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="documentReader">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>java:/documentReaderDatasource</jta-data-source>
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
               <property name="hibernate.hbm2ddl.auto" value="update"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>

               <!-- Inserted by me from the seambay example -->
               <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
               <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
               <!-- END Inserted by me from the seambay example -->
              
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/documentReaderEntityManagerFactory"/>
            </properties>
         </persistence-unit>
         
      </persistence>


      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:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation=
                      "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
                       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.0.xsd
                       http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.0.xsd
                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd
                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">

         <core:init debug="@debug@" jndi-pattern="@jndiPattern@"/>
          
         <core:manager concurrent-request-timeout="500"
                       conversation-timeout="120000"
                       conversation-id-parameter="cid"
                       parent-conversation-id-parameter="pid"/>
         
         <persistence:managed-persistence-context name="entityManager"
                                           auto-create="true"
                            persistence-unit-jndi-name="java:/documentReaderEntityManagerFactory"/>                         

         <drools:rule-base name="securityRules">
             <drools:rule-files>
                 <value>/security.drl</value>
             </drools:rule-files>
         </drools:rule-base>

         <security:identity security-rules="#{securityRules}" authenticate-method="#{authenticator.authenticate}" remember-me="true"/>
        
         <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="2525" username="test" password="test" />
             
         <!-- For use with jBPM pageflow or process management -->
         <!-- 
         <bpm:jbpm>
            <bpm:process-definitions></bpm:process-definitions>
            <bpm:pageflow-definitions></bpm:pageflow-definitions>
         </bpm:jbpm>
         -->
           
        
        
         <component name="newDocument" class="org.aPackage" scope="event"/>

          <!-- <transaction:ejb-transaction /> -->
        
      </components>


      Thank you in advance

        • 1. Re: ejb transactionEJBs, Web services, persistence problem
          Klearchos Klearchou Newbie
          Finally I found the problem.

          The namespace must be declared at the beginning of the XML.
          The name space is
          xmlns:transaction="http://jboss.com/products/seam/transaction"

          Thus the complete XML when we add the <transaction:ejb-transaction />
          at the components.xml is
          <?xml version="1.0" encoding="UTF-8"?>
          <components
                      xmlns="http://jboss.com/products/seam/components"
                      xmlns:transaction="http://jboss.com/products/seam/transaction"
                      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:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xsi:schemaLocation=
                          "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
                           http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
                           http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.0.xsd
                           http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.0.xsd
                           http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                           http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd
                           http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd">

          ....

          Possibly this will help people with the similar problem.

          • 2. Re: ejb transactionEJBs, Web services, persistence problem
            Piero Uniti Newbie

            I'm having the same problem, but your solution isn't working. I don't think it's a "solution" anyway... what's the difference between putting the namespace at the beginning or at the end...I may be wrong on this... Also your xml is incomplete, there no schemaLocation declaration for transaction.