0 Replies Latest reply on Sep 10, 2002 2:21 PM by Jens Schauder

    cmp2.0 relation

    Jens Schauder Newbie

      Hi
      I try to connect two cmp ejbs with a relation. After quite some try and error I managed to get it compiled and deployed. I can use both beans and I see the foreign key field in the database, but when I try to use the relation I get an exception of some proxy. I'm quite new at this and therefore really don't get what jboss is trying to tell me.
      I add the relevant pieces of code and the error message at the end.

      Evironment:
      Suse linux 8.0
      JBoss 3.0.2
      Sun JDK 1.4.0

      The whole thing is based on the template project

      TIA
      Spieler

      ------ Error Message of jboss ---------------------

      19:06:37,943 ERROR [LogInterceptor] EJBException, causedBy:
      java.lang.ClassCastException: $Proxy181
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.setInstanceValue(JDBCCMRFieldBridge.java:544)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.setValue(JDBCCMRFieldBridge.java:483)
      at org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocationHandler.invoke(EntityBridgeInvocationHandler.java:125)
      at org.jboss.proxy.compiler.Runtime.invoke(Runtime.java:59)
      at de.lineas.evaluator.entity.PropertyCMP$Proxy.setEvaluation()
      at de.lineas.evaluator.entity.PropertyBean.ejbPostCreate(PropertyBean.java:212)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:42)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:28)
      at java.lang.reflect.Method.invoke(Method.java:327)
      at org.jboss.ejb.plugins.CMPPersistenceManager.postCreateEntity(CMPPersistenceManager.java:284)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.postCreateEntity(CachedConnectionInterceptor.java:278)
      at org.jboss.ejb.EntityContainer.postCreateHome(EntityContainer.java:716)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:42)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:28)
      at java.lang.reflect.Method.invoke(Method.java:327)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke(EntityContainer.java:1170)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRelationInterceptor.java:95)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:308)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:152)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:107)
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:59)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:111)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:52)
      at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:105)
      at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:129)
      at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:487)
      at org.jboss.ejb.Container.invoke(Container.java:738)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1055)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
      at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:370)
      at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:28)
      at java.lang.reflect.Method.invoke(Method.java:327)
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:264)
      at sun.rmi.transport.Transport$1.run(Transport.java:151)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:147)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:463)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
      at java.lang.Thread.run(Thread.java:539)



      -------- The one side of the relationship ---------
      /**
      * get the properties belonging to this evaluation
      * @ejb:relation name="evaluation-property"
      * role-name="evaluation"
      */
      public abstract java.util.Collection getProperties();

      /**
      * set the evaluation to which this property belongs
      */
      public abstract void setProperties(java.util.Collection properties);

      -------- the one side of the relationship ---------

      /**
      * get the properties belonging to this evaluation
      * @ejb:relation name="evaluation-property"
      * role-name="evaluation"
      */
      public abstract java.util.Collection getProperties();

      /**
      * set the evaluation to which this property belongs
      */
      public abstract void setProperties(java.util.Collection properties);

      --- in the ejbPostCreate method of the same class I set the relationship ------------------------

      public void ejbPostCreate( String id, String description, Evaluation eval )
      {
      setEvaluation(eval);
      }


      ------ finally the code calling all this -----

      try {

      InitialContext lContext = new InitialContext();


      EvaluationHome evaluationHome = (EvaluationHome) lContext.lookup( "ejb/evaluator/Evaluation" );

      Evaluation evaluation = evaluationHome.create("eid1", "First test Evaluation");

      PropertyHome propertyHome = (PropertyHome) lContext.lookup( "ejb/evaluator/Property" );

      Property property = propertyHome.create("pid1", "First test Property");


      property = propertyHome.create("pid2", "Second test Property, first with evaluation", evaluation);


      System.out.println("done");

      } catch( Exception e ){

      e.printStackTrace();

      }