Results 1 to 7 of 7

Thread: Composite key using Hibernate Annotations

  1. #1
    Join Date
    Sep 2006
    Posts
    10

    Default 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. #2

  3. #3
    Join Date
    Jan 2008
    Posts
    8

    Default 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

  4. #4

    Default

    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.

  5. #5
    Join Date
    Jan 2011
    Posts
    2

    Default 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/

  6. #6
    Join Date
    Jan 2011
    Posts
    2

    Default

    Thank you !!
    Last edited by berbatov; Jan 24th, 2011 at 04:31 AM.

  7. #7
    Join Date
    Aug 2012
    Posts
    1

    Default

    Last edited by dhanaiahk; Aug 7th, 2012 at 07:36 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •