-->
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: Mapping generation with XDoclet
PostPosted: Wed Mar 17, 2004 11:13 pm 
Regular
Regular

Joined: Thu Jan 29, 2004 10:34 am
Posts: 52
Location: Austin, TX
i'm sure somebody following the top-design must have faced this problem during the generation of hibernate mapping xmls from pojo code marked with xdoclet tags.

in the Employee class i mark getName() as @hibernate.component. i mark all the getters in the Name class as @hibernate.property. when i give this an <hibernatedoclet> spin, i'll end up with a generated xml something like this.

Code:
<class name="Employee" table="employees">
        <id name="id">
            <generator class="sequence">
                <param name="sequence">employee_id_seq</param>
            </generator>
        </id>
        <property name="taxfileNumber"/>

        <component name="name" class="Name">
            <property name="firstName"/>
            <property name="initial"/>
            <property name="lastName"/>
        </component>
</class>


now if have another getter in Employee let's say getMotherName() which also returns a Name object. so i mark that with @hibernate.component as well.

now we get:
Code:
<class name="Employee" table="employees">
        <id name="id">
            <generator class="sequence">
                <param name="sequence">employee_id_seq</param>
            </generator>
        </id>
        <property name="taxfileNumber"/>

        <component name="name" class="Name">
            <property name="firstName"/>
            <property name="initial"/>
            <property name="lastName"/>
        </component>

        <component name="motherName" class="Name">
            <property name="firstName"/>
            <property name="initial"/>
            <property name="lastName"/>
        </component>
</class>


not surprisingly this causes causes :
[STDERR] net.sf.hibernate.MappingException: Repeated column in mapping for class com.alterpoint.aof.objects.platform.impl.ManagedElementImpl should be mapped with insert="false" update="false": firstName

does there seem to be a major flaw in my usage (though generated). how do i map multiple fields to the same <component>.

thanks
ravi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 19, 2004 6:10 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
There is no easy solution :(

_________________
Emmanuel


Top
 Profile  
 
 Post subject: alternative
PostPosted: Tue Mar 30, 2004 10:34 am 
Regular
Regular

Joined: Thu Jan 29, 2004 10:34 am
Posts: 52
Location: Austin, TX
the best alternative is to break it out and not use the @component concept for complex return types which occur more than once in a class. so instead of returning a complex type Name, i just model a separate object called Name and have relationships between Employee and Name (called name and motherName).

the other technique is to simply mark the complex type as @hibernate.property and make sure Name implement Serializable. this approach is acceptable if you don't need to directly make queries on the primitive value (String) that Name encapsulates. this is of course because Name will be a unusalbe blob in the database until it is deserialized.


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.