6 Replies Latest reply on May 31, 2004 1:04 AM by lahirukarunatilake

    Why the detail locals are not loading

    lahirukarunatilake Newbie

      Hi,

      The Jboss version : 3.2.3
      Database: mysql-5.0.0a-alpha-win

      Let me start with saying what I did. First created two entity beans which has one to many relationship. Then I created the cmr (relations) between those entities. Then from a session been i accessed the findByPrimaryKey method of the main (relation one side) entity been and tried to get the count of Locals in the detail entity bean throught the cmr field. Even though there are records in the detail table for the particular primary key the length function always return 0. Why these detail Locals are not get loaded.

      Thanks
      Lahiru

        • 1. Re: Why the detail locals are not loading
          ironbird Newbie

          Even beans are loaded ot not, the collection size is always the total count because the container get the ID's list before loading the beans.
          If the size is 0, then probably your relationship is not correctly defined.
          So, post the relevant snippets (descriptors, code) in order to investigate.

          • 2. Re: Why the detail locals are not loading
            lahirukarunatilake Newbie

            Following is my jbosscmp-jdbc

            <jbosscmp-jdbc>
             <defaults>
             </defaults>
            
             <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 <entity></entity> markup for those beans.
             -->
            
             <entity>
             <ejb-name>Site</ejb-name>
            
             <cmp-field>
             <field-name>description</field-name>
             <column-name>description</column-name>
            
             </cmp-field>
             <cmp-field>
             <field-name>siteCode</field-name>
             <column-name>site_code</column-name>
            
             </cmp-field>
            
            <!-- jboss 3.2 features -->
            <!-- optimistic locking does not express the exclusions needed -->
             </entity>
            
             <entity>
             <ejb-name>Location</ejb-name>
            
             <cmp-field>
             <field-name>description</field-name>
             <column-name>description</column-name>
            
             </cmp-field>
             <cmp-field>
             <field-name>locationCode</field-name>
             <column-name>location_code</column-name>
            
             </cmp-field>
             <cmp-field>
             <field-name>siteCode</field-name>
             <column-name>site_code</column-name>
            
             </cmp-field>
            
            <!-- jboss 3.2 features -->
            <!-- optimistic locking does not express the exclusions needed -->
             </entity>
            
             </enterprise-beans>
            
             <relationships>
             <ejb-relation>
             <ejb-relation-name>site-locations</ejb-relation-name>
            
             <ejb-relationship-role>
             <ejb-relationship-role-name>location-belongs_to-site</ejb-relationship-role-name>
             <key-fields/>
            
             </ejb-relationship-role>
             <ejb-relationship-role>
             <ejb-relationship-role-name>site-has-locations</ejb-relationship-role-name>
             <key-fields>
             <key-field>
             <field-name>siteCode</field-name>
             <column-name>site_code</column-name>
             </key-field>
             </key-fields>
            
             </ejb-relationship-role>
             </ejb-relation>
             </relationships>
            
            </jbosscmp-jdbc>
            


            This is the relationship section of the ejb-jar.xml
             <!-- Relationships -->
             <relationships >
             <ejb-relation >
             <ejb-relation-name>site-locations</ejb-relation-name>
            
             <ejb-relationship-role >
             <ejb-relationship-role-name>location-belongs_to-site</ejb-relationship-role-name>
             <multiplicity>Many</multiplicity>
             <relationship-role-source >
             <ejb-name>Location</ejb-name>
             </relationship-role-source>
             <cmr-field >
             <cmr-field-name>site</cmr-field-name>
             </cmr-field>
             </ejb-relationship-role>
            
             <ejb-relationship-role >
             <ejb-relationship-role-name>site-has-locations</ejb-relationship-role-name>
             <multiplicity>One</multiplicity>
             <relationship-role-source >
             <ejb-name>Site</ejb-name>
             </relationship-role-source>
             <cmr-field >
             <cmr-field-name>locations</cmr-field-name>
             <cmr-field-type>java.util.Collection</cmr-field-type>
             </cmr-field>
             </ejb-relationship-role>
            
             </ejb-relation>
             </relationships>
            


            Follwoing are the two beean codes
            SiteBean.java
             /**
             * DOCUMENT ME!
             *
             * @ejb.interface-method
             */
             public abstract void setLocations(Collection locations);
            
             /**
             * DOCUMENT ME!
             *
             * @return to be documented!
             *
             * @ejb.interface-method
             * @ejb.relation name="site-locations" role-name="site-has-locations"
             * @ejb.value-object aggregate="lk.ozone.o3synergy.o3storekeeper.common.to.location.LocationTO"
             * aggregate-name="Location" members="lk.ozone.o3synergy.o3storekeeper.bo.ejb.location.LocationLocal"
             * members-name="Locations" relation="external" type="java.util.Collection"
             */
             public abstract Collection getLocations();
            


            LocationBean.java
             /**
             * Sets the SiteLocal of the location
             *
             * @ejb.interface-method
             */
             public abstract void setSite(SiteLocal site);
            
             /**
             * Get the SiteLocal of the location
             *
             * @return SiteLocal
             *
             * @ejb.interface-method
             * @ejb.relation name="site-locations" role-name="location-belongs_to-site" cascade-delete="no"
             * @jboss.relation related-pk-field="siteCode" fk-column="site_code"
             */
             public abstract SiteLocal getSite();
            


            • 3. Re: Why the detail locals are not loading
              ironbird Newbie

              As your relation is defined through a value object, I cannot help you because I don't use it.
              But are you sure you are reach your bean through the generated value object class ?

              I suggest you to look at this topic too:
              http://www.jboss.org/index.html?module=bb&op=viewtopic&t=49921

              I Hope it helps.

              • 4. Re: Why the detail locals are not loading
                lahirukarunatilake Newbie

                Okay. But I did it without the value object too. still I get the same resault. I removed all the xdoclet code generation and added the remote interface and the home interface manually.

                follwoing are the snippists.
                Ejb-jar.xml relation ships

                 <relationships>
                 <ejb-relation>
                 <ejb-relation-name>site-location</ejb-relation-name>
                 <ejb-relationship-role>
                 <description>site</description>
                 <ejb-relationship-role-name>SiteRelationshipRole</ejb-relationship-role-name>
                 <multiplicity>One</multiplicity>
                 <relationship-role-source>
                 <description>site</description>
                 <ejb-name>Site</ejb-name>
                 </relationship-role-source>
                 <cmr-field>
                 <description>location</description>
                 <cmr-field-name>location</cmr-field-name>
                 <cmr-field-type>java.util.Collection</cmr-field-type>
                 </cmr-field>
                 </ejb-relationship-role>
                 <ejb-relationship-role>
                 <description>location</description>
                 <ejb-relationship-role-name>LocationRelationshipRole</ejb-relationship-role-name>
                 <multiplicity>Many</multiplicity>
                 <relationship-role-source>
                 <description>location</description>
                 <ejb-name>Location</ejb-name>
                 </relationship-role-source>
                 </ejb-relationship-role>
                 </ejb-relation>
                 </relationships>
                


                jbosscmp-jdbc.xml
                 <relationships>
                 <ejb-relation>
                 <ejb-relation-name>site-location</ejb-relation-name>
                 <ejb-relationship-role>
                 <ejb-relationship-role-name>SiteRelationshipRole</ejb-relationship-role-name>
                 <key-fields>
                 <key-field>
                 <field-name>siteCode</field-name>
                 <column-name>site_code</column-name>
                 </key-field>
                 </key-fields>
                 </ejb-relationship-role>
                 <ejb-relationship-role>
                 <ejb-relationship-role-name>LocationRelationshipRole</ejb-relationship-role-name>
                 </ejb-relationship-role>
                 </ejb-relation>
                 </relationships>
                


                SiteBean.java
                
                .
                .
                .
                 public abstract void setLocation(Collection location);
                 public abstract Collection getLocation();
                .
                .
                .
                



                • 5. Re: Why the detail locals are not loading
                  ironbird Newbie

                  No, definitively, I don't see any error in your descriptors.
                  Perhaps the error is a database issue.
                  You are using MySQL 5.0.0A which is not a stable version. Try with the production release 4.0.X.
                  Perhaps the <datasource-mapping> tag in jbosscmp-jdbc is not set, or the mySQL mapping is not compatible with the 5.0.X version.

                  • 6. Re: Why the detail locals are not loading
                    lahirukarunatilake Newbie

                    Thanx for the help I figured it out. As you have said it was a database issue. After I changed the table types of my mysql datbase the ejb worked as normal......

                    Thanx again,

                    Lahiru.