-->
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.  [ 5 posts ] 
Author Message
 Post subject: One-to-one mapping on same table (can't use <component>
PostPosted: Sun Dec 07, 2003 7:15 pm 
Regular
Regular

Joined: Tue Dec 02, 2003 6:25 pm
Posts: 61
Location: Dallas, TX
I'm having a similar problem to this post. although the component approach does not seem to work.

I have two classes: PropertyReportOrder and PropertyReport. They have a bidirectional one-to-one relationship, and both must be mapped to the property_report table.

If I map one as a component, then it doesn't seem that I would be able to access the other one directly, which I will need to be able to do. At some times, users will want to start with a PropertyReport and see its PropertyReportOrder, and at other times they will need to start with the order and then get to the report.

I thought about doing separate class/component mappings for BOTH classes, but it seems a little weird. Also, that solution breaks for PropertyReport because it needs to have mapped subclasses, and <component> does not allow <joined-subclass> nodes. (and that's another problem -- described in this posting.)

So far the only thing I can get to work is to use <many-to-one> mappings between the two classes.


Top
 Profile  
 
 Post subject: Re: One-to-one mapping on same table (can't use <componen
PostPosted: Mon Dec 08, 2003 4:53 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
wfassett wrote:
If I map one as a component, then it doesn't seem that I would be able to access the other one directly, which I will need to be able to do.

Components have no life out of their master entity, then component is not what you want.

wfassett wrote:
At some times, users will want to start with a PropertyReport and see its PropertyReportOrder, and at other times they will need to start with the order and then get to the report.

<parent> tag of component might help.

wfassett wrote:
I thought about doing separate class/component mappings for BOTH classes, but it seems a little weird.

I can't follow you. Why not having a bidirectional 1-to-1 mapping between PropertyReport (entity) and PropertyReportOrder (entity) wo component at all ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: One-to-one mapping on same table (can't use <componen
PostPosted: Mon Dec 08, 2003 11:29 am 
Regular
Regular

Joined: Tue Dec 02, 2003 6:25 pm
Posts: 61
Location: Dallas, TX
Yes a 1-1 mapping would be ideal, except that Hibernate does not appear to allow a one-to-one mapping when both entities come from the same table. I get a class cast exception from Hibernate.

I've read other threads that say that the obvious solution when people need a 1-1 on the same table is to use component, but it does not seem appropriate here, and it will not work if my component needs to have subclasses.

So I've been using many-to-one, which also seems inappropriate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 12:25 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
actually, you could use a custom persister to do this. Just override getIdentifierSpace() to return something other than the tablename.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 1:33 pm 
Regular
Regular

Joined: Tue Dec 02, 2003 6:25 pm
Posts: 61
Location: Dallas, TX
That was easy! I just had getIdentifierSpace() return the class name. Works great.


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