5 Replies Latest reply on Nov 13, 2006 11:29 AM by Dennis Meyer

    address CMP beans from session bean in other JAR but same EA

    Dennis Meyer Newbie

      I've got a problem addressing a CMP bean in a different Eclipse project (the projects should be seperated). Both projects should work fine, but when I try to address the CMP Bean (like I do with the local beans as well) I get the error below.

      We have git two EJB projects: core-ejb and persistence-ejb that I have both in a EAR. When I just copy the CMP to my core-ejb project all works fine, but not when I try to access it cross-JAR!

      I'm using Entity Manager injection out og an Stateless session bean

      @PersistenceContext(unitName="ios") private EntityManager em;
      ...
      ...
       Query query = em.createQuery("SELECT c FROM Config c WHERE c.configClass =:configClass " +
       "AND c.instanceId =:instanceId AND c.deleted=0");
       query.setParameter("configClass", configClassName);
       query.setParameter("instanceId", instanceId);
       try{
       conf = (Config)query.getSingleResult();
       }
      ...
      ...
      


      I also tried with
      SELECT * FROM com.teec.ios.ejb.cmp.Config c WHERE...

      but this also didn't work!



      This should be an easy one for an EJB - Guru, so please help!



      Exception in thread "main" javax.ejb.EJBTransactionRolledbackException: javax.ejb.EJBTransactionRolledbackException: java.lang.IllegalArgumentException: Unknown entity: com.teec.ios.ejb.cmp.Config
       at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:89)
       at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:196)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:54)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:181)
       at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:79)
       at $Proxy129.createConfig(Unknown Source)
       at com.teec.ios.core.ejb.session.MailManagerBean.createMailConfig(MailManagerBean.java:250)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:109)
       at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:192)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:81)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.stateful.StatefulContainer.dynamicInvoke(StatefulContainer.java:308)
       at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:104)
       at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
       at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:828)
       at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:681)
       at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:358)
       at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:412)
       at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:239)
       at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:190)
       at org.jboss.remoting.Client.invoke(Client.java:525)
       at org.jboss.remoting.Client.invoke(Client.java:488)
       at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:55)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:55)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:65)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.stateful.StatefulRemoteProxy.invoke(StatefulRemoteProxy.java:133)
       at $Proxy1.createMailConfig(Unknown Source)
       at com.teec.ios.core.client.MailClient.createMailConfig(MailClient.java:63)
       at com.teec.ios.core.client.MailClient.main(MailClient.java:75)


        • 1. Re: address CMP beans from session bean in other JAR but sam
          milan wölke Newbie

          Could it be that you have the Config entity bean in both of your jars inside the ear? Or maybe there is another deployment unit in the deploy dir containing this entity bean?

          We had the same exception when deploying the same entity bean twice with different ears.

          Regards, Milan Wölke

          • 2. Re: address CMP beans from session bean in other JAR but sam
            Dennis Meyer Newbie

            Zuerst: Danke nach Berlin!

            I checked the Beans and the Beans are not a double deployment. They even deploy once and they deploy without errors.

            I think I just missed something. Maybe it's the Deployment descriptor I was not aware of. All my both JARs have is

            persitence.xml (both look the same):

            <persistence>
             <persistence-unit name="ios">
             <jta-data-source>java:/oldios</jta-data-source>
             </persistence-unit>
            </persistence>
            


            The Entity Beans in JAR #1:

            package com.teec.ios.ejb.cmp;
            import java.io.Serializable;
            
            @javax.persistence.Entity
            @javax.persistence.Table(name = "config")
            public class Config implements Serializable {
            
             private int id;
             @javax.persistence.Id
             @javax.persistence.Column(name = "id")
             public int getId() {
             return id;
             }
            
             public void setId(int id) {
             this.id = id;
             }
             ...
            }
            


            The Session Beans in JAR #2 like this Test Bean:

            package com.teec.ios.core.ejb.session;
            ...
            @Stateful
            public class MailManagerBean implements MailManagerRemote, MailManagerLocal {
             ...
             @EJB private ConfigManagerLocal config;
             ...
             @PersistenceContext(unitName="ios") private EntityManager em;
             ...
            
             public void createMailConfig(MailConfig conf, String configInstanceID) throws ConfigExistsAlreadyException{
             try {
             System.out.println("Entities found : "+em.createQuery("from com.teec.ios.ejb.cmp.Config c").getResultList().size());
             System.out.println("Entities found : "+em.createQuery("from Config c").getResultList().size());
             } catch (Exception e) {
             e.printStackTrace();
             }
             }
            }
            


            When running the Example bean, I get
            12:59:28,304 WARN [QuerySplitter] no persistent classes found for query class: from com.teec.ios.ejb.cmp.Config c
            
            
            12:59:28,304 INFO [STDOUT] Entities found : 0
            12:59:28,507 ERROR [STDERR] javax.persistence.PersistenceException: org.hibernate.hql.ast.QuerySyntaxException: Config is not mapped [from Config c]
            
            
            12:59:28,507 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:562)
            12:59:28,507 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:80)
            12:59:28,507 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManager.createQuery(TransactionScopedEntityManager.java:127)
            12:59:28,507 ERROR [STDERR] at com.teec.ios.core.ejb.session.MailManagerBean.createMailConfig(MailManagerBean.java:247)
            12:59:28,507 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            12:59:28,507 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            12:59:28,507 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            12:59:28,507 ERROR [STDERR] at java.lang.reflect.Method.invoke(Unknown Source)
            12:59:28,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:109)
            12:59:28,507 ERROR [STDERR] at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
            12:59:28,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            12:59:28,507 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
            12:59:28,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            12:59:28,507 ERROR [STDERR] at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
            12:59:28,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            12:59:28,507 ERROR [STDERR] at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
            12:59:28,507 ERROR [STDERR] at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:192)
            12:59:28,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            12:59:28,507 ERROR [STDERR] at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
            12:59:28,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            12:59:28,507 ERROR [STDERR] at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:81)
            12:59:28,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            12:59:28,507 ERROR [STDERR] at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
            12:59:28,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            12:59:28,507 ERROR [STDERR] at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
            12:59:28,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            12:59:28,507 ERROR [STDERR] at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
            12:59:28,507 ERROR [STDERR] at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
            12:59:28,507 ERROR [STDERR] at org.jboss.ejb3.stateful.StatefulContainer.dynamicInvoke(StatefulContainer.java:308)
            12:59:28,507 ERROR [STDERR] at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:104)
            12:59:28,507 ERROR [STDERR] at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
            12:59:28,507 ERROR [STDERR] at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:828)
            12:59:28,507 ERROR [STDERR] at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:681)
            12:59:28,507 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:358)
            12:59:28,507 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:412)
            12:59:28,507 ERROR [STDERR] at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:239)
            12:59:28,507 ERROR [STDERR] Caused by: org.hibernate.hql.ast.QuerySyntaxException: Config is not mapped [from Config c]
            12:59:28,507 ERROR [STDERR] at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
            12:59:28,507 ERROR [STDERR] at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
            12:59:28,507 ERROR [STDERR] at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
            12:59:28,507 ERROR [STDERR] at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:267)
            12:59:28,507 ERROR [STDERR] at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3049)
            12:59:28,507 ERROR [STDERR] at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2938)
            12:59:28,507 ERROR [STDERR] at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
            12:59:28,507 ERROR [STDERR] at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
            12:59:28,507 ERROR [STDERR] at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
            12:59:28,507 ERROR [STDERR] at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
            12:59:28,507 ERROR [STDERR] at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:227)
            12:59:28,507 ERROR [STDERR] at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:159)
            12:59:28,507 ERROR [STDERR] at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:110)
            12:59:28,507 ERROR [STDERR] at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
            12:59:28,507 ERROR [STDERR] at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
            12:59:28,507 ERROR [STDERR] at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
            12:59:28,507 ERROR [STDERR] at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
            12:59:28,507 ERROR [STDERR] at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
            12:59:28,507 ERROR [STDERR] at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1586)
            12:59:28,507 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:77)
            12:59:28,507 ERROR [STDERR] ... 34 more
            
            


            Anyway I do not have a deployment descriptor.
            1) Di I need a deployment descriptor (a single JAR-Application doesn't need it as anyrhing works well)?
            2) What do I need to include in the deployment descritor in the Entity JAR?
            3) What do I need to include in the deployment descritor in the Session Bean JAR?
            4) Is it correct to have the same persistence.xml?

            If anyone could provide some sample files this would be most helpful!!!

            Thanks a lot,
            Dennis


            • 3. Re: address CMP beans from session bean in other JAR but sam
              Dennis Meyer Newbie

              The deployment descriptors seem not to be the problem as the EJB 3 Spec states that it's not needed:

              Definition of the Java language metadata annotations that can be used to annotate EJB applications.
              These metadata annotations are targeted at simplifying the developer?s task, at reducing
              the number of program classes and interfaces the developer is required to implement, and
              at eliminating the need for the developer to provide an EJB deployment descriptor.


              • 4. Re: address CMP beans from session bean in other JAR but sam
                Dennis Meyer Newbie

                ANYWAY:

                ! ! ! I DO ALSO APPRECIATE DEPLOYMENT DESCRIPTOR EXAMLES ! ! !

                Thanks!

                • 5. Re: address CMP beans from session bean in other JAR but sam
                  Dennis Meyer Newbie

                  So, die Lösung ist gefunden:

                  -Man benötigt nur einen persistence.xml - Eintrag in dem JAR mit den Entities, die andere kann leer bleiben.
                  -Als Verweis benutzt man dann

                  @PersistenceContext(unitName="../NAMEDESANDERENJARS.jar#PERSISTENCEUNITNAME") private EntityManager em;
                  

                  Also z.B.
                  @PersistenceContext(unitName="../teec-ios-persistence-ejb.jar#ios") private EntityManager em;
                  

                  Das ganze ist dann in der JSR 220: Enterprise JavaBeansTM,Version 3.0 beschrieben und zwar in Abschnitt 16.10.2 (einfach suchen nach "#").
                  ---------------------------------
                  UPS, just noticed I was qwriting in german - so again in english :-)

                  So, die Lösung ist gefunden:

                  -You only need a single persistence.xml - entry in the entity JAR, the other persitence.xml can stay empty.
                  -The reference works as follows
                  @PersistenceContext(unitName="../NAMEDESANDERENJARS.jar#PERSISTENCEUNITNAME") private EntityManager em;
                  

                  For example:
                  @PersistenceContext(unitName="../teec-ios-persistence-ejb.jar#ios") private EntityManager em;
                  

                  You can find more information here: JSR 220: Enterprise JavaBeansTM,Version 3.0 Paragraph 16.10.2 (just search for "#").