3 Replies Latest reply on May 7, 2007 9:01 PM by headjoog2

    Hibernate / Foreign Key Example?

      First, read the disclaimer: I'm new at Hibernate so there's likely an oversight on my part.

      Can anyone offer an example or some pointers on this scenario: Let's take the CRM example included with FDS. There is a company table and employee table. Let's extend the CRM sample and look at the company table. Perhaps I want to have a company table and then add an industry table with a foreign key (instead of the static array that is populated in the original example) to the company table. Simple one (industry)-to-many (companies) relationship, right?

      So - my questions:

      1) What's the suggested way to populate the industry combo box with industry names? Do you just add the query during your app initialization process?

      2) (Bigger question for me) - how do you resolve the foreign key in Flex? Do you have to build write the code in AS to resolve the foreign key for industry and then populate the company table with the proper industry id? I know you set up your company POJO with the Industry object and I know Hibernate will handle some of this, but I'm unclear on an elegant way to do this through Flex.

      I'd REALLY, REALLY appreciate any discussion....thanks,

      Now I've been able to set up Hibernate to query / populate single tables per the example. BUT....if I wanted to populate the combo box
        • 1. Re: Hibernate / Foreign Key Example?
          aBill Level 1

          You should have another industries destination and your company should have a industry property. In your destination, you should have its association defined
          <identity property="id"/>
          <!-- it is many companies map to same industry -->
          <many-to-one destination="allIndustries" property="industry"/>

          your Company.as should have
          var public industry:Industry;

          company.hbm.xml should have
          <many-to-one name="industry" access="field" class="your.java.IndustryClass" column="industryId" cascade="save-update"/>

          Company table
          id, companyName, industryId .....

          William Chan

          • 2. Hibernate / Foreign Key Example?
            aBill Level 1

            For the comboBox, you can bind it to a managed collection(filled by dataservice)

            <mx:ComboBox id="cb" dataProvider="{allIndustries}" labelField="name" change="company.industry = cb.selectedItem as Industry"
            selectedItem="{comboBoxSelect(allIndustries, 'name', company)}" prompt="Select an Industry"/>

            private static function comboBoxSelect(ac:ICollectionView, field:String, value:*):Object
            for (var i:Number = 0; i < ac.length; i++)
            if(ac [field] == value.industry.name)
            return ac
            return null;
            • 3. Re: Hibernate / Foreign Key Example?
              headjoog2 Level 1
              Thanks so much - I was able to get this working. If I want to show industry name in a data grid, along with the company name. do you refer to it in the same manner as the combo box? When I try to display in the data grid I just get the [Object object] displayed.

              Again - thanks!