1 Reply Latest reply on Sep 30, 2007 12:37 AM by jaikiran pai

    transaction problem

    Amer Ramamni Newbie

      I am testing a session bean class.
      and when I run my client .. I keep getting this exception

      xception in thread "main" javax.ejb.EJBTransactionRolledbackException: EntityManager must be access within a transaction
       at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
       at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor
      .java:62)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.jav
      a:77)
       at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationIntercepto
      r.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:1
      06)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:278)
       at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
       at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandl
      er.java:82)
       at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:734)
       at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:560)
      
       at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:369)
       at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:165)
      Caused by: javax.persistence.TransactionRequiredException: EntityManager must be access within a tra
      nsaction
       at org.jboss.ejb3.entity.ManagedEntityManagerFactory.verifyInTx(ManagedEntityManagerFactory.
      java:150)
      
      


      this is my client class... all I want to do is add an object in the table
      public class KBClient {
      
       public static void main(String[] args) {
      
       KBClient c = new KBClient();
       ClassificationRemote r = c.lookupNewClassificationBean();
       KnowledgeBase first = new KnowledgeBase();
       first.setKnowledgeID(200);
       first.setKnowledgeName("AmerDemo");
       first.setKnowledgeCategory("Classification");
       first.setProjectID(new Project(88));
       first.setDeleted(0);
       r.addKnowledgeBase(first); //Exception occurs
       }
      
       private ClassificationRemote lookupNewClassificationBean() {
       try {
       Hashtable props = new Hashtable();
       props.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
       props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
       props.put("java.naming.provider.url", "localhost");
       Context c = new InitialContext(props);
       return (ClassificationRemote) c.lookup("ClassificationBeanFinal/remote");
       }
       catch(NamingException ne) {
       Logger.getLogger(getClass().getName()).log(Level.SEVERE,"exception caught" ,ne);
       throw new RuntimeException(ne);
       }
       }
      }
      


      This is the function in the session bean

       @PersistenceContext private EntityManager em;
      
       public void addKnowledgeBase(KnowledgeBase kb){
       System.out.println("YAAAHOOOOOOO");
       em.persist(kb);
       }
      


      a little bit of help would be appreicated.
      Thanks