1 Reply Latest reply on Jan 3, 2003 7:16 AM by Ben

    Problem using CMR in 1-1 relationship

    Badi Newbie

      Hello,

      I'm trying to setup a 1-1 relationship using CMR. It seems that JBoss correctly creates the tables including the foreign keys, but when I try to call the setter for the CMR field (e.g setCompte()), JBoss throws an exception :

      05:26:21,103 ERROR [LogInterceptor]TransactionRolledbackException, causedBy:
      java.lang.ClassCastExceptionb: $Proxy170
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.JBDCCMRFieldBridge.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.Runtine.invoke(Runtine.java:59)
      at com.Banque.entities.ClientCMP$Proxy.setCompte()
      ...


      I've attached the ejb-jar & jbosscmp-jdbc.xml files; I'm using JBoss 3.0.4 & MySQL. Any suggestions would be greatly appreciated =o)

      ejb-jar.cmp:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

      <ejb-jar >

      No Description.
      <display-name>Generated by XDoclet</display-name>

      <enterprise-beans>

      <!-- Session Beans -->

      <![CDATA[No Description.]]>

      <ejb-name>Banque</ejb-name>

      com.Banque.session.BanqueHome
      com.Banque.session.Banque
      <ejb-class>com.Banque.session.BanqueSession</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>

      <ejb-ref>
      <ejb-ref-name>ejb/Client</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      ClientHome
      com.Banque.entities.Client
      <ejb-link>Client</ejb-link>
      </ejb-ref>

      <ejb-ref>
      <ejb-ref-name>ejb/Compte</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      CompteHome
      com.Banque.entities.Compte
      <ejb-link>Compte</ejb-link>
      </ejb-ref>



      <!--
      To add session beans that you have deployment descriptor info for, add
      a file to your merge directory called session-beans.xml that contains
      the markup for those beans.
      -->

      <!-- Entity Beans -->

      <![CDATA[No Description.]]>

      <ejb-name>Compte</ejb-name>

      com.Banque.entities.CompteHome
      com.Banque.entities.Compte

      <ejb-class>com.Banque.entities.CompteCMP</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>com.Banque.entities.ComptePK</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Compte</abstract-schema-name>

      <cmp-field><field-name>uid</field-name></cmp-field>
      <cmp-field><field-name>solde</field-name></cmp-field>




      <![CDATA[No Description.]]>

      <ejb-name>Client</ejb-name>

      com.Banque.entities.ClientHome
      com.Banque.entities.Client

      <ejb-class>com.Banque.entities.ClientCMP</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>com.Banque.entities.ClientPK</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Client</abstract-schema-name>

      <cmp-field><field-name>password</field-name></cmp-field>
      <cmp-field><field-name>email</field-name></cmp-field>
      <cmp-field><field-name>nom</field-name></cmp-field>
      <cmp-field><field-name>prenom</field-name></cmp-field>



      <!--
      To add entity beans that you have deployment descriptor info for, add
      a file to your merge directory called entity-beans.xml that contains
      the markup for those beans.
      -->

      <!-- Message Driven Beans -->
      <!--
      To add message driven beans that you have deployment descriptor info for, add
      a file to your merge directory called message-driven-beans.xml that contains
      the <message-driven></message-driven> markup for those beans.
      -->

      </enterprise-beans>

      <!-- Relationships -->


      <ejb-relation>
      <ejb-relation-name>Client-Compte</ejb-relation-name>
      <foreign-key-mapping/>

      <ejb-relationship-role>
      <ejb-relationship-role-name>Client-has-Compte</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>Client</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>compte</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>

      <ejb-relationship-role>
      <ejb-relationship-role-name>Compte-has-Client</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>Compte</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>client</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>

      </ejb-relation>





      <!-- Assembly Descriptor -->
      <assembly-descriptor >

      <!-- finder permissions -->

      <method-permission>


      <ejb-name>Compte</ejb-name>
      <method-name>*</method-name>

      </method-permission>

      <method-permission>


      <ejb-name>Client</ejb-name>
      <method-name>*</method-name>

      </method-permission>

      <method-permission>


      <ejb-name>Banque</ejb-name>
      <method-name>*</method-name>

      </method-permission>


      <!-- transactions -->

      <container-transaction>

      <ejb-name>Client</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>

      <container-transaction>

      <ejb-name>Compte</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>

      <container-transaction>

      <ejb-name>Banque</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>


      <!-- finder transactions -->
      </assembly-descriptor>

      </ejb-jar>


      jbosscmp-jdbc.cmp:

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 3.0//EN" "http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_3_0.dtd">

      <jbosscmp-jdbc>

      java:/MySqlDS
      <datasource-mapping>mySQL</datasource-mapping>


      <enterprise-beans>


      <ejb-name>Compte</ejb-name>
      <table-name>comptes</table-name>

      <!--
      To define load groups for this entity, write a file named
      jbosscmp-jdbc-load-CompteBean.xml and put it in
      your mergedir. Write it according to the following DTD slice:
      <!ELEMENT load-groups (load-group+)>
      <!ELEMENT load-group (load-group-name, description?, field-name+)>
      <!ELEMENT load-group-name (#PCDATA)>
      <!ELEMENT description (#PCDATA)>
      <!ELEMENT field-name (#PCDATA)>
      <!ELEMENT eager-load-group (#PCDATA)>
      <!ELEMENT lazy-load-groups (load-group-name+)>
      -->




      <ejb-name>Client</ejb-name>
      <table-name>clients</table-name>

      <!--
      To define load groups for this entity, write a file named
      jbosscmp-jdbc-load-ClientBean.xml and put it in
      your mergedir. Write it according to the following DTD slice:
      <!ELEMENT load-groups (load-group+)>
      <!ELEMENT load-group (load-group-name, description?, field-name+)>
      <!ELEMENT load-group-name (#PCDATA)>
      <!ELEMENT description (#PCDATA)>
      <!ELEMENT field-name (#PCDATA)>
      <!ELEMENT eager-load-group (#PCDATA)>
      <!ELEMENT lazy-load-groups (load-group-name+)>
      -->




      </enterprise-beans>


      <ejb-relation>
      <ejb-relation-name>Client-Compte</ejb-relation-name>
      <foreign-key-mapping/>

      <ejb-relationship-role>
      <ejb-relationship-role-name>Client-has-Compte</ejb-relationship-role-name>

      <key-fields>
      <key-field>
      <field-name>nom</field-name>
      <column-name>client_nom</column-name>
      </key-field>
      <key-field>
      <field-name>prenom</field-name>
      <column-name>client_prenom</column-name>
      </key-field>
      </key-fields>

      </ejb-relationship-role>

      <ejb-relationship-role>
      <ejb-relationship-role-name>Compte-has-Client</ejb-relationship-role-name>

      <key-fields>
      <key-field>
      <field-name>uid</field-name>
      <column-name>compte_uid</column-name>
      </key-field>
      </key-fields>

      </ejb-relationship-role>

      </ejb-relation>




      <dependent-value-classes>

      </dependent-value-classes>


      </jbosscmp-jdbc>


      ---

      Badi