Hibernate Cartridge

Bi-directional, one-to-many, ordered lists don't work

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 3.1-RC1
  • Fix Version/s: None
  • Component/s: None
  • Description:
    Hide
    If defining a bi-directional, one-to-many association that is supposed to be an "ORDERED" list, the proper code to allow Hibernate to manage the index is not generated.

    Discussed in this post ( http://galaxy.andromda.org/forum/viewtopic.php?p=3909#3909 ), the relevant information:

    Per the Hibernate FAQ at http://www.hibernate.org/193.html ....

    Assume I've set the namespace property associationEndCollectionIndexName to the value of "listPosition".

    If using Hibernate 2, the following additional code would need to be generated in the child entity's Java classes IF doing a bi-directional, one-to-many, ordered association:

    Code:
    private int listPosition;

    public int getListPosition()
      {
        return this.get<nameOfParentEntity>().get<nameOfThisEntityInParent>().indexOf(this);
      }

      private void setListPosition(int index)
      {
        // not used, calculated value, see getIndex() method
      }


    Also, the "listPosition" attribute would need to be added to the child entity's Hibernate HBM file.

    For Hibernate 3, the following change would be needed:

    in the parent entity's HBM file, where the <list> mapping is, the "inverse" attribute should be set to FALSE (it is currently set to "true").

    in the child entity's HBM file, where the <many-to-one> mapping is, the attributes "update" and "insert" both need to be set to false.
    Show
    If defining a bi-directional, one-to-many association that is supposed to be an "ORDERED" list, the proper code to allow Hibernate to manage the index is not generated. Discussed in this post ( http://galaxy.andromda.org/forum/viewtopic.php?p=3909#3909 ), the relevant information: Per the Hibernate FAQ at http://www.hibernate.org/193.html .... Assume I've set the namespace property associationEndCollectionIndexName to the value of "listPosition". If using Hibernate 2, the following additional code would need to be generated in the child entity's Java classes IF doing a bi-directional, one-to-many, ordered association: Code: private int listPosition; public int getListPosition()   {     return this.get<nameOfParentEntity>().get<nameOfThisEntityInParent>().indexOf(this);   }   private void setListPosition(int index)   {     // not used, calculated value, see getIndex() method   } Also, the "listPosition" attribute would need to be added to the child entity's Hibernate HBM file. For Hibernate 3, the following change would be needed: in the parent entity's HBM file, where the <list> mapping is, the "inverse" attribute should be set to FALSE (it is currently set to "true"). in the child entity's HBM file, where the <many-to-one> mapping is, the attributes "update" and "insert" both need to be set to false.
  1. bi-dir-ordered-list.patch
    (30 kB)
    Joel Kozikowski
    24/Aug/05 6:08 PM
  2. HibernateMetafacadeModel.xml.zip
    (21 kB)
    Joel Kozikowski
    24/Aug/05 6:08 PM

Activity

Hide
Joel Kozikowski added a comment - 24/Aug/05 6:08 PM
Attached is DIFF file with corresponding Metafacde model to address this issue.
Show
Joel Kozikowski added a comment - 24/Aug/05 6:08 PM Attached is DIFF file with corresponding Metafacde model to address this issue.
Hide
Carlos Cuenca added a comment - 24/Aug/05 6:14 PM
Hi Joel,

thanks for the patch, I will review it tonight.

Carlos Cuenca
Show
Carlos Cuenca added a comment - 24/Aug/05 6:14 PM Hi Joel, thanks for the patch, I will review it tonight. Carlos Cuenca

People

Dates

  • Created:
    16/Aug/05 10:52 PM
    Updated:
    24/Aug/05 6:14 PM