-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate-mapping (XML) to Hibernate Annotations
PostPosted: Tue Jul 15, 2008 2:55 am 
Newbie

Joined: Tue Jul 15, 2008 2:40 am
Posts: 2
Hello!

In our project we use Hibernate Annotations and we want to use a many-to-many relation with an additional field.
For that reason we used the example provided in the caveatemptor project: CategorizedItem.hbm.xml. This is exactly what we need but not with an Mapping-XML since we are using annotations.

Code:
<hibernate-mapping package="org.hibernate.auction.model">

<class name="CategorizedItem"
      table="CATEGORIZED_ITEM"
      lazy="true">

   <composite-id name="id" class="CategorizedItem$Id"
                 access="org.hibernate.auction.persistence.DirectSetAccessor"
                 unsaved-value="any">

        <key-property name="categoryId"
                      access="field"
                      column="CATEGORY_ID"
                      length="16"/>

        <key-property name="itemId"
                      access="field"
                      column="ITEM_ID"
                      length="16"/>
   </composite-id>

   <property   name="dateAdded"
            column="DATE_ADDED"
            type="java.util.Date"
            update="false"
            not-null="true"
            access="org.hibernate.auction.persistence.DirectSetAccessor"/>

    <property   name="username"
                column="USERNAME"
                type="string"
                update="false"
                not-null="true"
                access="org.hibernate.auction.persistence.DirectSetAccessor"/>

    <many-to-one    name="category"
                    insert="false"
                    update="false"
                    not-null="true"
                    access="org.hibernate.auction.persistence.DirectSetAccessor"
                    column="CATEGORY_ID"/>

    <many-to-one    name="item"
                    insert="false"
                    update="false"
                    not-null="true"
                    access="org.hibernate.auction.persistence.DirectSetAccessor"
                    column="ITEM_ID"/>

</class>

</hibernate-mapping>


How does the correct object with annotations look like? We tried it a view times but it doesn't work! Can somebody help us?

Thanks in advance!

Best regards, Stefan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 16, 2008 3:00 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi Stefan,

Is it this you are after http://forum.hibernate.org/viewtopic.php?t=987912? Adding additional data to the join table. Have a look at this thread - it contains some examples.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 16, 2008 8:24 am 
Newbie

Joined: Tue Jul 15, 2008 2:40 am
Posts: 2
Thank you for the link! Everything seems to be clear now ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.