7 Replies Latest reply on Mar 7, 2003 3:43 PM by ABAZIOU

    Problem with CMR (1:1)

    ABAZIOU Newbie

      I have problem with CMR fields (no problem on deploy) : errors at runtime when calling setter or getter methods on a CMR field.

      I tried to resolved the problem from other thread in forum but didn't find the trick (i think my deployment file are correct).

      The relation is a 1:1 between a User en a UserInfo

      The generated tables are :
      user ( email, password, info)
      userinfo ( infoid, dept, firstname, lastname, ...)

      Here is the relation in ejb-jar.xml :

      <ejb-relation >
      <ejb-relation-name>UserHasUserInfo</ejb-relation-name>
      <!-- bidirectional -->
      <ejb-relationship-role >
      <ejb-relationship-role-name>UserHasUserInfo</ejb-relationship-role-name>
      One
      <relationship-role-source >
      <ejb-name>User</ejb-name>
      </relationship-role-source>
      <cmr-field >
      <cmr-field-name>userInfo</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role >
      <ejb-relationship-role-name>UserInfoPartOfUser</ejb-relationship-role-name>
      One
      <cascade-delete/>
      <relationship-role-source >
      <ejb-name>UserInfo</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>


      Here is the relation in jbooscmp-jdbc.xml :


      <ejb-relation>
      <ejb-relation-name>UserHasUserInfo</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>UserHasUserInfo</ejb-relationship-role-name>
      <key-fields/>

      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>UserInfoPartOfUser</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>infoId</field-name>
      <column-name>info</column-name>
      </key-field>
      </key-fields>

      </ejb-relationship-role>
      </ejb-relation>



      Source calling EJB :

      User user = userHome.create(email, password);
      UserInfo info = infoHome.create(firstName, middleName,
      lastName, email, dept, workPhone, extention,
      homePhone, isEmployee);
      user.setUserInfo(info); // Here is the error

      Beginning of trace :

      17:05:26,259 ERROR [LogInterceptor] TransactionRolledbackException, causedBy:java.lang.ClassCastException
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.setInstanceValue(JDBCCMRFieldBridge.java:551)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMRFieldBridge.setValue(JDBCCMRFieldBridge.java:483)
      at org.jboss.ejb.plugins.cmp.bridge.EntityBridgeInvocationHandler.invoke(EntityBridgeInvocationHandler.java:126)
      at org.jboss.proxy.compiler.Runtime.invoke(Runtime.java:59)
      at fr.free.banks.UserCMP$Proxy.setUserInfo()
      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:324)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke(EntityContainer.java:1194)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCRelationInterceptor.invoke(JDBCRelationInterceptor.java:95)
      at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchronizationInterceptor.java:297)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
      at org.jboss.ejb.plugins.EntityReentranceInterceptor.invoke(EntityReentranceInterceptor.java:90)
      at org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterceptor.java:163)
      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:107)
      at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:69)
      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:107)
      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)
      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:60)
      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:130)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:204)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)
      at org.jboss.ejb.Container.invoke(Container.java:712)
      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1058)
      at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
      at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:98)
      at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:102)
      at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:77)
      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:80)
      at org.jboss.proxy.ejb.EntityInterceptor.invoke(EntityInterceptor.java:116)
      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:76)
      at $Proxy81.setUserInfo(Unknown Source)
      at fr.free.banks.UserManagementBean.addUser(UserManagementBean.java:94)

        • 1. Re: Problem with CMR (1:1)
          Loïc Newbie

          I think your EJB 'UserInfo' should be a Local one.
          I have heard that JBoss CMR (with CMP 2.0) can only deal with the local interfaces of EJBs.

          All my EJBs follow this rule and everythink's ok for me.

          • 2. Re: Problem with CMR (1:1)
            ABAZIOU Newbie

            You're right !
            It's working now. (i've changed my two entity beans User
            and UserInfo - they are accessed by a session Bean UserManagement)

            Thanks

            • 3. Re: Problem with CMR (1:1)
              Mynt Newbie

              I have a problem regarding this example.
              The method .setUserInfo(userInfo) works just fine, but .getUserInfo() doesn't. What I really don't understand is the fact that I don't even have an exception, the code just blocks.

              Both User and UserInfo beans are local, and reentrant flag is true.

              Thx

              • 4. Re: Problem with CMR (1:1)
                ABAZIOU Newbie

                To be exact, it's in EJB/CMP 2.0 Specs to work with local interface when accessing CMR fields, so it's not a restriction of JBoss

                • 5. Re: Problem with CMR (1:1)
                  ABAZIOU Newbie

                  Mynt, can you post sample code or some trace ?

                  I plan to write a tutorial on this sample (it fully works now) for JBoss using Eclipse and Lomboz plugin, EJBDoclet (with code assist), describing plugins i've installed.

                  Original tutorial is from Rick Hightower : http://www.rickhightower.com/ejbcmpcmrtut.html, perhaps it can help you

                  • 6. Re: Problem with CMR (1:1)
                    Mynt Newbie


                    Here is the method in question:
                    public UserValue[] getUsersInfo() {
                    try{
                    ArrayList userList = new ArrayList(50);
                    System.out.println("before findAll");
                    Collection collection = userHome.findAll();
                    System.out.println("after findAll count:" + collection.size());
                    Iterator iterator = collection.iterator();
                    int i=0;
                    while(iterator.hasNext()){
                    System.out.println("pas i ="+ i++);
                    UserLocal user = (UserLocal)iterator.next();
                    System.out.println("user" + user);
                    UserInfoLocal info = user.getUserInfo();//here where it stops
                    System.out.println("userinfo" + info);
                    UserValue userValue = new UserValue(user.getEmail());
                    copyUserInfo(userValue, info);
                    userList.add(userValue);
                    }
                    System.out.println("userList created");
                    return (UserValue[])
                    userList.toArray(new UserValue[userList.size()]);

                    } catch (FinderException e){
                    throw new EJBException
                    ("Unable to get list of users ", e);
                    }
                    catch(Exception e){
                    throw new EJBException("Some exception", e);
                    }
                    }

                    On the server output:
                    before findAll
                    after findAll count:4
                    pas i =0
                    userjava:comp/partone/User andy@rickhightower.com

                    On the client here's what he says:

                    java.rmi.RemoteException: java.rmi.RemoteException: timeout expired waiting for an instance; nested exception is:
                    java.rmi.RemoteException: timeout expired waiting for an instance

                    java.rmi.RemoteException: timeout expired waiting for an instance


                    Thx

                    • 7. Re: Problem with CMR (1:1)
                      ABAZIOU Newbie

                      No problem with this part of code : it's work for me with the same.

                      Give more code (bean User an UserInfo and relation content of ejb-jar jbosscmp-jdbc files)

                      Have you check the content of table after call to setUserInfo ?