Announcement Announcement Module
Collapse
No announcement yet.
Composite key using Hibernate Annotations Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Composite key using Hibernate Annotations

    Hey all,

    Can someone give me a proper example for Composite key using Hibernate Annoations.

    suppose

    Table1 : Product { id(pk), name }
    Table2 : Item { id(pk), name }

    Table12 :ProductItem{id(pk) , productId(fk) , itemId(fk) }

    pk - primary key
    fk - foreign key

    can anyone implement above define tables using hibernate annotaions

  • #2
    You'll find an example here:

    http://java-aap.blogspot.com/2006/04...composite.html

    Comment


    • #3
      CompositeKey Mapping problem in Hibernate

      Hi All,

      I Am also trying to know , how to do mapping in hbm for a composite key.
      I have two tables.From Table A we are using two columns as composite key.And that composite key is the forgen key in Table B.Please tell somebody how to do the mapping in hbm and how to write the enity


      Thnx in advance
      Regards
      Debapriya

      Comment


      • #4
        Recently I need to define composite unique key in hibernate mapping.

        The example lower is illustrating this:

        <hibernate-mapping>
        <class name="name.platonov.MyType" table="My_TYPE">
        <id name="id" column="ID" />
        <property name="name" column="NAME" />
        <property name="prop1" column="PROP1" unique-key="UK_MY_TYPE" />
        <property name="prop2" column="PROP2" unique-key="UK_MY_TYPE" />
        </class>
        </hibernate-mapping>

        In this hibernate mapping prop1 and prop2 are defined as composite unique key.

        Comment


        • #5
          Composite key using hibernate Annotation

          its always better to use Annotation instead of using HBM files to map the tables.. I just went through one site http://j2eereference.com , which explain this with simple example .

          http://j2eereference.com/2011/01/imp...and-hibernate/

          Comment


          • #6
            Thank you !!
            Last edited by berbatov; Jan 24th, 2011, 05:31 AM.

            Comment


            • #7
              I too have similar requirement. Thanks for sharing useful links.

              ___________
              Dhanaiah
              Apple Health Club | Best Tips to Stay Healthy
              Best of Android | Android News | Best Android Apps | Android Games | Android Devices
              Last edited by dhanaiahk; Aug 7th, 2012, 08:36 AM.

              Comment

              Working...
              X