-->
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.  [ 6 posts ] 
Author Message
 Post subject: Xdoclet tag for a map-key
PostPosted: Thu Oct 12, 2006 12:19 am 
Beginner
Beginner

Joined: Sat Jul 08, 2006 2:58 pm
Posts: 26
I'm trying to learn to use xdoclet tags.

In my mapping file I want to use a xdoclet tag to generate the following line in my mapping file:


<map-key column=speaker_index" type="string" length="20" />

Should I use @hibernate.collection-key-column to generate this? If so then when should I use @hibernate.collection-key???


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 9:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I would suggest you look at some of the XDoclet samples and just try out a few keys and see what is generated for you. See http://xdoclet.sourceforge.net/xdoclet/tags/hibernate-tags.html
. I would expect the collection-key would be correct but I have not tested it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 10:05 am 
Beginner
Beginner

Joined: Sat Jul 08, 2006 2:58 pm
Posts: 26
I did find an example, here's the mapping I came up with.

Code:
/**
    * @hibernate.map
    * @hibernate.collection-key column="personID"
    * @hibernate.collection-index column="address_type" type="string"
    * @hibernate.collection-one-to-many class="com.chisq.common.bo.Address"
    *
    */

   @SuppressWarnings("unchecked")
   public Map getAddresses() {
      return addresses;
   }

   public void setAddresses(Map addresses) {
      this.addresses = addresses;
   }



Now, however, when I run it through my ant task it generates everything but the mapping for addresses. Anybody have an idea of what's wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 2:07 pm 
Beginner
Beginner

Joined: Sat Jul 08, 2006 2:58 pm
Posts: 26
OK, as suggested earlier and after lots of experimenting I can now get xdoclet to generate a mapping.

In my Person pojo, I did the following:

Code:
/**
    * @hibernate.map
    * @hibernate.collection-key column="PersonID"
    * @hibernate.collection-index column="address_type" type="string"
    * @hibernate.collection-one-to-many class="com.chisq.common.bo.Address"
    */
   public Map getAddresses() {
      return addresses;
   }

   public void setAddresses(Map addresses) {
      this.addresses = addresses;
   }


which xdoclet generates:


Code:
       <map
            name="addresses"
            lazy="false"
            sort="unsorted"
            cascade="none"
        >

            <key
                column="PersonID"
            >
            </key>

            <index
                column="address_type"
                type="string"
            />

            <one-to-many
                  class="com.chisq.common.bo.Address"
            />

        </map>



Which is all great! However, when I look in the schema that gets generated, I expected to see a table created called Addresses but I don't see one. Nor do I see any kind of column in the Person table that references Addresses. So I must not understand how maps work in hibernate. Could someone please enlighted me?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 2:14 pm 
Beginner
Beginner

Joined: Sat Jul 08, 2006 2:58 pm
Posts: 26
What I see is a personID column that gets put in the Address table! I'm confused as to why this is happening. Help!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 12, 2006 11:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Looks right to me. You said that you have the Address Table and the personID (and I hope the Index) was on the Address Table. The Address Table is the Many side and personID is a foreign key to the Person table - all is good. I suggest you read a little more on Many-to-one relationships.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.