4 Replies Latest reply on Aug 6, 2009 7:41 AM by Wolfgang Knauf

    Noob in EJB3 :D

    Michał Szylar Newbie

      Hello,

      I have entity bean eg:

      @Entity
      public class Apple()
      {
      @Id
      public Integer id;
      public String name;
      }


      Stateless Bean:

      @Stateless
      public class FruitManager implements FruitManagerRemote()
      {
       public apple getAppleById(int id)
       {
       Apple apple=em.find(apple.class,1);
       return apple;
       }
      }


      Client Code:

      public class Client {
       public static void main(String[] args) {
       Properties properties = new Properties();
       //init of properties are here for jndi
       Context context;
       try
       {
       context = new InitialContext();
       FruitManagerRemote fruit = (FruitManagerRemote)context.lookup("FruitManager/Remote");
       Apple apple=fruit.getAppleById(1);
       }
      }



      Why I can obtain Apple object at client side?
      There are some error at client side (I can add stack trace tomorow).

      If I made an Apple in FruitManager I can get it from client, but if it was persisted it can be send to client? Is it right behaviour?

      Maybe at client side should I remove annotations?

      Any ideas?

        • 1. Re: Noob in EJB3 :D
          Michał Szylar Newbie

          According to this: http://www.roseindia.net/ejb/entity-bean-example.shtml it should work.

          Is important that client is out of container? I doubt so.

          Any ideas?

          • 2. Re: Noob in EJB3 :D
            Jeroen Wenting Newbie

            Never trust roseindia. That site is terrible!

            It does indeed matter whether the client is in- or outside the container. The creation of the InitialContext for example is quite different, requires more parameters when doing so from outside the container (things like where to find the container).

            • 3. Re: Noob in EJB3 :D
              Michał Szylar Newbie

              initial context:

               Properties properties = new Properties();
               properties.put("java.naming.factory.initial",
               "org.jnp.interfaces.NamingContextFactory");
               properties.put("java.naming.factory.url.pkgs",
               "=org.jboss.naming:org.jnp.interfaces");
               properties.put("java.naming.provider.url", "10.132.15.227:1099");
               Context context;


              stack trace:
              Useraccount [id=1, profiles=null, userLogin=admin, userPassMd5=admin]
              Exception in thread "main" javax.ejb.EJBException: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
               at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:77)
               at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
               at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:421)
               at org.jboss.ejb3.session.InvokableContextClassProxyHack._dynamicInvoke(InvokableContextClassProxyHack.java:53)
               at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:91)
               at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
               at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:891)
               at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:744)
               at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:697)
               at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:524)
               at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:232)
              Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
               at org.hibernate.type.StringType.toString(StringType.java:67)
               at org.hibernate.type.NullableType.nullSafeToString(NullableType.java:117)
               at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:158)
               at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
               at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:61)
               at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:514)
               at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1589)
               at org.hibernate.loader.Loader.doQuery(Loader.java:696)
               at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
               at org.hibernate.loader.Loader.doList(Loader.java:2228)
               at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
               at org.hibernate.loader.Loader.list(Loader.java:2120)
               at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
               at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361)
               at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
               at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148)
               at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
               at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:67)
               at com.ca.mailing.ProfileManagerBean.getUsProfileById(ProfileManagerBean.java:73)
               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.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111)
               at org.jboss.ejb3.EJBContainerInvocationWrapper.invokeNext(EJBContainerInvocationWrapper.java:69)
               at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:73)
               at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:59)
               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.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:72)
               at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_4256705.invoke(InvocationContextInterceptor_z_fillMethod_4256705.java)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:88)
               at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_4256705.invoke(InvocationContextInterceptor_z_setup_4256705.java)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:68)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
               at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:190)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:186)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:421)
               at org.jboss.ejb3.session.InvokableContextClassProxyHack._dynamicInvoke(InvokableContextClassProxyHack.java:53)
               at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:91)
               at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
               at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:891)
               at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:744)
               at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:697)
               at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:524)
               at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:232)
               at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:211)
               at org.jboss.remoting.Client.invoke(Client.java:1724)
               at org.jboss.remoting.Client.invoke(Client.java:629)
               at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:60)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:65)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
               at $Proxy5.invoke(Unknown Source)
               at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:207)
               at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:164)
               at $Proxy4.getUsProfileById(Unknown Source)
               at com.ca.mailing.client.UserClient.main(UserClient.java:86)
               at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:72)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:65)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:74)
               at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)
               at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)
               at $Proxy5.invoke(Unknown Source)
               at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:207)
               at org.jboss.ejb3.proxy.impl.handler.session.SessionProxyInvocationHandlerBase.invoke(SessionProxyInvocationHandlerBase.java:164)
               at $Proxy4.getUsProfileById(Unknown Source)
               at com.ca.mailing.client.UserClient.main(UserClient.java:86)


              any ideas why I get this?


              • 4. Re: Noob in EJB3 :D
                Wolfgang Knauf Master

                Hi,

                according to the exception, there is a "java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String" in code called from "com.ca.mailing.ProfileManagerBean.getUsProfileById(ProfileManagerBean.java:73)". So maybe your ID property has type "int" while you try to load some data with a "string" parameter. Take a look at this code, and if you don't see a solution, post "getUsProfileById" and your entity bean.

                Best regards

                Wolfgang