-->
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.  [ 7 posts ] 
Author Message
 Post subject: [Xdoclet][composite-id]composite-id code using XDoclet
PostPosted: Thu Mar 02, 2006 12:02 pm 
Newbie

Joined: Thu Mar 02, 2006 10:59 am
Posts: 8
Location: Paris
Generating composite-id code using XDoclet.

I want to generate my *.hbm.xml file with Xdoclet

I see Xdoclet @hibernate.composite-id, but no example
Is there anybody which tried this ?


Top
 Profile  
 
 Post subject: sources
PostPosted: Thu Mar 02, 2006 1:01 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Looking at the XDoclet template might give you pretty good idea

xdoclet-1.2.3/modules/hibernate/src/xdoclet/modules/hibernate/resources/hibernate.xdt
Code:
<XDtHibernate:ifHasCompositeId>
        <composite-id
            name="<XDtMethod:propertyName/>"
            class="<XDtMethod:methodTagValue tagName="hibernate.id" paramName="class" default="<XDtMethod:methodType/>"/>"
            <XDtMethod:ifHasMethodTag tagName="hibernate.id" paramName="unsaved-value">
            unsaved-value="<XDtMethod:methodTagValue tagName="hibernate.id" paramName="unsaved-value" values="any,none"/>"
            </XDtMethod:ifHasMethodTag>
        >
        <XDtClass:pushClass value="<XDtMethod:methodType/>">
            <XDtMethod:forAllMethods superclasses="true" sort="true">
                 <XDtMethod:ifHasMethodTag tagName="hibernate.property">
                     <key-property
                        name="<XDtMethod:propertyName />"
                        type="<XDtMethod:methodTagValue tagName="hibernate.property" paramName="type" default="<XDtMethod:methodType/>"/>"
                        column="<XDtMethod:methodTagValue tagName="hibernate.property" paramName="column" default="<XDtMethod:propertyName/>"/>"
                       <XDtMethod:ifHasMethodTag tagName="hibernate.property" paramName="length">
                        length="<XDtMethod:methodTagValue tagName="hibernate.property" paramName="length" />"
                       </XDtMethod:ifHasMethodTag>
                />
                </XDtMethod:ifHasMethodTag>

                <XDtMethod:ifHasMethodTag tagName="hibernate.many-to-one">
                    <key-many-to-one
                        name="<XDtMethod:propertyName/>"
                        class="<XDtMethod:methodTagValue tagName="hibernate.many-to-one" paramName="class" default="<XDtMethod:methodType/>" />"
                        column="<XDtMethod:methodTagValue tagName="hibernate.many-to-one" paramName="column" default="<XDtMethod:propertyName/>"/>"
                    />
                </XDtMethod:ifHasMethodTag>
            </XDtMethod:forAllMethods>
        </XDtClass:pushClass>
        </composite-id>
    </XDtHibernate:ifHasCompositeId>



It looks like your compositeID class should have its relevant methods marked as hibernate.property and they will be included in the composite ID.


If you do not quite like what gets generated you can easily create modified version of the template locally and supply it to the build process

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 1:33 pm 
Newbie

Joined: Thu Mar 02, 2006 10:59 am
Posts: 8
Location: Paris
ok Thanks,
But i don't want to create a CompositeID class for each class,
i have just my object and his primary keys & properties
is it possible ?


Top
 Profile  
 
 Post subject: XDoclet
PostPosted: Thu Mar 02, 2006 2:45 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
It looks like currently XDoclet does not have that feature but you can easily do it yourself , for example you can put hibernate.key-property marks on methods and use them by adding lines like this:

Code:

            <XDtMethod:forAllMethods superclasses="true" sort="true">
                 <XDtMethod:ifHasMethodTag tagName="hibernate.key-property">
                     <key-property
                        name="<XDtMethod:propertyName />"
                        type="<XDtMethod:methodTagValue tagName="hibernate.property" paramName="type" default="<XDtMethod:methodType/>"/>"
                        column="<XDtMethod:methodTagValue tagName="hibernate.property" paramName="column" default="<XDtMethod:propertyName/>"/>"
                       <XDtMethod:ifHasMethodTag tagName="hibernate.property" paramName="length">
                        length="<XDtMethod:methodTagValue tagName="hibernate.property" paramName="length" />"
                       </XDtMethod:ifHasMethodTag>
                />
                </XDtMethod:ifHasMethodTag>

                <XDtMethod:ifHasMethodTag tagName="hibernate.key-many-to-one">
                    <key-many-to-one
                        name="<XDtMethod:propertyName/>"
                        class="<XDtMethod:methodTagValue tagName="hibernate.many-to-one" paramName="class" default="<XDtMethod:methodType/>" />"
                        column="<XDtMethod:methodTagValue tagName="hibernate.many-to-one" paramName="column" default="<XDtMethod:propertyName/>"/>"


/>
</XDtMethod:ifHasMethodTag>
</XDtMethod:forAllMethods>

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 10:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The CVS version allow this functionality (but I have not tried it). Please note that the hibernate recommended method is to use separate composite key class.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 3:49 am 
Regular
Regular

Joined: Tue May 04, 2004 6:15 am
Posts: 51
As others have said its better to use a class.
The way you do this is you simply declare a

Code:
    /**
    * @hibernate.id
    */


for your #getId() method returning the class to use as a "composite id".

On your "composite id" class you simply declare as

Code:
    /**
    * @hibernate.property
    */


the properties of your POJO that you want to use as property keys.

Don't forget to override #equals() and #hashCode()

_________________
eu:life
http://www.eulife.gr


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 4:53 am 
Newbie

Joined: Thu Mar 02, 2006 10:59 am
Posts: 8
Location: Paris
Thanks to everybody
Finally, i use the Cue's method with a composite class,
that i have put in my Object, as a inner Class


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.