4 Replies Latest reply on Oct 8, 2003 2:06 PM by jesper mortensen

    CMP of foreign key gives some sort of cached object

    jesper mortensen Newbie

      I have two CMP beans with a 0..* relation

      In the 1- end of the relation when I look in the database I have a value like:

      \000\005sr\000$org.jboss.invocation.MarshalledValueJ\231\014\000\000xpw\000\000\000\000\005sr\000+org.jboss.proxy.ejb.handle.EntityHandleImpl'3/\236\237\003\000\003L\000\002idt\000\022Ljava/lang/Object;L\000\007jndiEnvt\000\025Ljava/util/Hashtable;L\000\010jndiNamet\000\022Ljava/lang/String;xpt\000 13a93971c0a8012100d767dc36424fcbpt\000\027ejb/glasws/Organisationx.\227\003x

      where I expected to find the pk of the other end of the relation

      what am I doint wrong ?

        • 1. Re: CMP of foreign key gives some sort of cached object
          Alex Paransky Newbie

          It sounds like your relational field in the database is a String. You have not properly defined the relation in your ejb-jar deployment descriptor. The setXXX operation takes and object, but simply executes toString() on it.

          Post your ejb-jar.xml as well your jbosscmp-jdbc.xml file...

          -AP_

          • 2. Re: CMP of foreign key gives some sort of cached object
            jesper mortensen Newbie

            Thank you for your helt I think you are right:

            jbosscmp-jdbc.xml: -------------------------------------------------

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

            <jbosscmp-jdbc>

            java:/PostgresDS
            <datasource-mapping>PostgreSQL</datasource-mapping>


            <enterprise-beans>

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


            <ejb-name>Contact</ejb-name>
            <create-table>true</create-table>
            <table-name>Contacts</table-name>

            <cmp-field>
            <field-name>organisation</field-name>

            </cmp-field>
            <cmp-field>
            <field-name>id</field-name>

            </cmp-field>
            <cmp-field>
            <field-name>fname</field-name>

            </cmp-field>
            <cmp-field>
            <field-name>lname</field-name>

            </cmp-field>

            <!-- jboss 3.2 features -->
            <!-- optimistic locking does not express the exclusions needed -->



            <ejb-name>Organisation</ejb-name>
            <create-table>true</create-table>
            <table-name>Organisations</table-name>

            <cmp-field>
            <field-name>id</field-name>

            </cmp-field>
            <cmp-field>
            <field-name>name</field-name>

            </cmp-field>

            <!-- jboss 3.2 features -->
            <!-- optimistic locking does not express the exclusions needed -->


            </enterprise-beans>


            <ejb-relation>
            <ejb-relation-name>ContactsInOrganisationRelation</ejb-relation-name>

            <ejb-relationship-role>
            <ejb-relationship-role-name>ContactInOrganisation</ejb-relationship-role-name>
            <key-fields/>

            </ejb-relationship-role>
            <ejb-relationship-role>
            <ejb-relationship-role-name>OrganisationHasContacts</ejb-relationship-role-name>
            <key-fields>
            <key-field>
            <field-name>id</field-name>
            <column-name>organisation</column-name>
            </key-field>
            </key-fields>

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


            </jbosscmp-jdbc>


            ejb-jar.xml ----------------------------------------------------------

            <?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 >

            <![CDATA[No Description.]]>
            <display-name>Generated by XDoclet</display-name>

            <enterprise-beans>

            <!-- Session Beans -->

            <![CDATA[]]>
            <display-name>Contact Actions EJB</display-name>

            <ejb-name>ContactActions</ejb-name>

            org.glasws.interfaces.ContactActionsHome
            org.glasws.interfaces.ContactActions
            <local-home>org.glasws.interfaces.ContactActionsLocalHome</local-home>
            org.glasws.interfaces.ContactActionsLocal
            <ejb-class>org.glasws.ws.ContactActionsBean</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Container</transaction-type>




            <![CDATA[]]>
            <display-name>Contact Management EJB</display-name>

            <ejb-name>ContactManagement</ejb-name>

            org.glasws.interfaces.ContactManagementHome
            org.glasws.interfaces.ContactManagement
            <local-home>org.glasws.interfaces.ContactManagementLocalHome</local-home>
            org.glasws.interfaces.ContactManagementLocal
            <ejb-class>org.glasws.ws.ContactManagementBean</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Container</transaction-type>



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

            <!-- Entity Beans -->

            <![CDATA[]]>
            <display-name>Contact EJB</display-name>

            <ejb-name>Contact</ejb-name>

            org.glasws.interfaces.ContactHome
            org.glasws.interfaces.Contact
            <local-home>org.glasws.interfaces.ContactLocalHome</local-home>
            org.glasws.interfaces.ContactLocal

            <ejb-class>org.glasws.ejb.ContactCMP</ejb-class>
            <persistence-type>Container</persistence-type>
            <prim-key-class>java.lang.String</prim-key-class>
            False
            <cmp-version>2.x</cmp-version>
            <abstract-schema-name>glasws</abstract-schema-name>
            <cmp-field >
            <![CDATA[]]>
            <field-name>organisation</field-name>
            </cmp-field>
            <cmp-field >
            <![CDATA[]]>
            <field-name>id</field-name>
            </cmp-field>
            <cmp-field >
            <![CDATA[]]>
            <field-name>fname</field-name>
            </cmp-field>
            <cmp-field >
            <![CDATA[]]>
            <field-name>lname</field-name>
            </cmp-field>
            <primkey-field>id</primkey-field>


            <query-method>
            <method-name>findAll</method-name>
            <method-params>
            </method-params>
            </query-method>
            <ejb-ql><![CDATA[SELECT OBJECT(Contacts) FROM glasws Contacts]]></ejb-ql>


            <query-method>
            <method-name>findByName</method-name>
            <method-params>
            <method-param>java.lang.String</method-param>
            <method-param>java.lang.String</method-param>
            </method-params>
            </query-method>
            <ejb-ql><![CDATA[SELECT OBJECT(Contacts) FROM glasws Contacts WHERE Contacts.fname=?1 AND Contacts.lname=?2]]></ejb-ql>

            <!-- Write a file named ejb-finders-ContactBean.xml if you want to define extra finders. -->



            <![CDATA[]]>
            <display-name>Organisation EJB</display-name>

            <ejb-name>Organisation</ejb-name>

            org.glasws.interfaces.OrganisationHome
            org.glasws.interfaces.Organisation
            <local-home>org.glasws.interfaces.OrganisationLocalHome</local-home>
            org.glasws.interfaces.OrganisationLocal

            <ejb-class>org.glasws.ejb.OrganisationCMP</ejb-class>
            <persistence-type>Container</persistence-type>
            <prim-key-class>java.lang.String</prim-key-class>
            False
            <cmp-version>2.x</cmp-version>
            <abstract-schema-name>Organisation</abstract-schema-name>
            <cmp-field >
            <![CDATA[]]>
            <field-name>id</field-name>
            </cmp-field>
            <cmp-field >
            <![CDATA[]]>
            <field-name>name</field-name>
            </cmp-field>
            <primkey-field>id</primkey-field>


            <query-method>
            <method-name>findAll</method-name>
            <method-params>
            </method-params>
            </query-method>
            <ejb-ql><![CDATA[SELECT OBJECT(Organisations) FROM glasws Organisations]]></ejb-ql>

            <!-- Write a file named ejb-finders-OrganisationBean.xml if you want to define extra finders. -->


            <!--
            To add entity beans that you have deployment descriptor info for, add
            a file to your XDoclet 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 XDoclet 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>ContactsInOrganisationRelation</ejb-relation-name>

            <ejb-relationship-role >
            <ejb-relationship-role-name>ContactInOrganisation</ejb-relationship-role-name>
            Many
            <relationship-role-source >
            <ejb-name>Contact</ejb-name>
            </relationship-role-source>
            <cmr-field >
            <cmr-field-name>organisation</cmr-field-name>
            </cmr-field>
            </ejb-relationship-role>

            <ejb-relationship-role >
            <ejb-relationship-role-name>OrganisationHasContacts</ejb-relationship-role-name>
            One
            <relationship-role-source >
            <ejb-name>Organisation</ejb-name>
            </relationship-role-source>
            <cmr-field >
            <cmr-field-name>contacts</cmr-field-name>
            <cmr-field-type>java.util.Collection</cmr-field-type>
            </cmr-field>
            </ejb-relationship-role>

            </ejb-relation>


            <!-- Assembly Descriptor -->
            <assembly-descriptor >
            <!--
            To add additional assembly descriptor info here, add a file to your
            XDoclet merge directory called assembly-descriptor.xml that contains
            the <assembly-descriptor></assembly-descriptor> markup.
            -->

            <!-- finder permissions -->

            <!-- finder permissions -->

            <!-- finder permissions -->

            <!-- finder permissions -->

            <!-- transactions -->
            <container-transaction >

            <ejb-name>Contact</ejb-name>
            <method-intf>LocalHome</method-intf>
            <method-name>create</method-name>
            <method-params>
            <method-param>java.lang.String</method-param>
            <method-param>java.lang.String</method-param>
            </method-params>

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

            <ejb-name>Contact</ejb-name>
            <method-intf>Home</method-intf>
            <method-name>create</method-name>
            <method-params>
            <method-param>java.lang.String</method-param>
            <method-param>java.lang.String</method-param>
            </method-params>

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

            <ejb-name>Contact</ejb-name>
            <method-intf>LocalHome</method-intf>
            <method-name>create</method-name>
            <method-params>
            <method-param>java.lang.String</method-param>
            <method-param>java.lang.String</method-param>
            <method-param>org.glasws.interfaces.Organisation</method-param>
            </method-params>

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

            <ejb-name>Contact</ejb-name>
            <method-intf>Home</method-intf>
            <method-name>create</method-name>
            <method-params>
            <method-param>java.lang.String</method-param>
            <method-param>java.lang.String</method-param>
            <method-param>org.glasws.interfaces.Organisation</method-param>
            </method-params>

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

            <ejb-name>Contact</ejb-name>
            <method-intf>Local</method-intf>
            <method-name>getOrganisation</method-name>
            <method-params>
            </method-params>

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

            <ejb-name>Organisation</ejb-name>
            <method-intf>LocalHome</method-intf>
            <method-name>create</method-name>
            <method-params>
            <method-param>java.lang.String</method-param>
            </method-params>

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

            <ejb-name>Organisation</ejb-name>
            <method-intf>Home</method-intf>
            <method-name>create</method-name>
            <method-params>
            <method-param>java.lang.String</method-param>
            </method-params>

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

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

            </ejb-jar>


            xdoclet in ContactBean.java: ------------------------------------

            /**
            *
            * @return Return the organisation this contact is in
            *
            * @ejb.interface-method view-type = "local"
            *
            * @ejb.transaction type = "required"
            *
            * @ejb.relation
            * name = "ContactsInOrganisationRelation"
            * role-name = "ContactInOrganisation"
            * target-role-name = "OrganisationHasContacts"
            * target-ejb = "Organisation"
            *
            * @jboss.relation
            * related-pk-field = "id"
            * fk-column = "organisation"
            *
            * @ejb.persistent-field
            *
            * @ejb.value-object
            *
            *
            *
            */
            public abstract Organisation getOrganisation();
            public abstract void setOrganisation(Organisation organisation);


            xdoclet in OrganisationBean.java:---------------------------------

            /**
            * @return return contacts in this organisation
            *
            * @ejb.interface-method view-type = "both"
            *
            * @ejb.relation
            * name = "ContactsInOrganisationRelation"
            * role-name = "OrganisationHasContacts"
            * target-role-name = "ContactInOrganisation"
            * target-cascade-delete = "no"
            * target-ejb = "Contact"
            *
            * @ejb.value-object
            * aggregate = "org.glasws.valueobjects.ContactValue"
            * aggregate-name = "ContactsInOrg"
            * members = "org.glasws.interfaces.ContactLocal"
            * members-name = "ContactLocal"
            * relation = "external"
            * type = "Collection"
            *
            */
            public abstract Collection getContacts();

            /**
            *
            * @ejb.interface-method view-type = "local"
            *
            *
            */
            public abstract void setContacts(Collection contacts);

            • 3. Re: CMP of foreign key gives some sort of cached object
              Alex Paransky Newbie

              "organization" should not be a <cmp-field> in your contact object. It's already a CMR field.

              Remove it from your deployment as a <cmp-field>

              -AP_

              • 4. Re: CMP of foreign key gives some sort of cached object
                jesper mortensen Newbie

                Problem solved
                Thank you for your assistance