-->
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.  [ 4 posts ] 
Author Message
 Post subject: One class mapped to multiple multiple tables - xdoclet/ejb3
PostPosted: Tue May 09, 2006 4:57 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Hi,

I have a POJO (IncomeEntry) which is involved in two parent-child relationships (one-to-many):

Code:
Payslip 1------* IncomeEntry

PayProfile 1------* IncomeEntry


I therefore need map the IncomeEntry class to multiple tables (payslip_incomeentry and payprofile_incomeentry). I am using X-Doclet to generate my mappings.

My questions are:
1) Since the table that the class is mapped to is defined on the class using the x-doclet tag:
Code:
* @hibernate.class
*       proxy = "com.acme.domain.IncomeEntry"
*       table = "incomeEntry"


is there any way to model this relationship without merging a custom mapping document into the generated hibernate-cfg.xml file?

2) Is this modelling possible with ejb3 annotations?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 8:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Maybe I don't quite understand your problem. I would appear tro me that you just need to map an inhertence hierarchy for the tables in question with the sub-domain objects containing the one-to-many mappings. This is possible with XDoclet (hence HBM) and Annotations.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 12:42 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Hi

There is no implicit inheritance hierarchy in the classes involved - so I don't understand how mapping a hierarchy would help me. Perhaps you could elaborate?

PayProfile and Payslip are two completely different classes. Both however have a relationship with an IncomeEntry in a one-to-many manner. In the case of a Payslip, the IncomeEntries represent the payslips income entries, whereas in the case of the PayProfile the IncomeEntries represents the payprofiles income entry.

To solve the issue I have created two new classes, PayslipIncomeEntry and PayProfileIncomeEntry. These classes are mapped to payslip_incomeentry and payprofile_incomeentry respectively. The IncomeEntry class is then mapped as a component in each of these classes. This allows me to re-use the class.

i.e.
Code:
<hibernate-mapping>
    <class
        name="PayslipIncomeEntry" table="payslip_incomeentry">

        <id name="id" column="id" type="java.lang.Long" unsaved-value="null">
            <generator class="native" /
        </id>

        <component name="entry" class="IncomeEntry">
           ....
        </component>
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 8:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Several options - If I understand correct the issue.
1) Could in Java have class PayslipIncomeEntry extend IncomeEntry and map it to the table - no need to have it as a component.
2) H3 only - Use the class mapping attribute 'entityname' see http://www.hibernate.org/hib_docs/v3/reference/en/html/mapping.html#mapping-declaration-class


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