-->
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: Problem mapping two FK into one Propery
PostPosted: Tue Jun 27, 2006 11:20 am 
Newbie

Joined: Sat Jun 03, 2006 5:36 pm
Posts: 8
Hibernate version:3.1.3

I have DB with Two Tables

Path
Point

Path contains:
-id
-startPointId
-endPointId

Point contains:
-id

I need to make bidirectional mapping between these objects, but in Point I need to make only one field:

Point.getAllStartEndPaths()

How should I map it?

I neeed only to read this field (bag or anything what it can be)

I cannot make any view into DB, because DB is readonly :(


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 7:05 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Map two sets, an internalStartPointSet and an internalEndPointSet. Have getAllStartEndPaths() return "new ArrayList(getInternalStartPointSet()).addAll(getInternalEndPointSet())" or equivalent.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: sql optimized
PostPosted: Wed Jun 28, 2006 1:05 am 
Newbie

Joined: Sat Jun 03, 2006 5:36 pm
Posts: 8
Thanks for reply ;-)
That solution is correct (I was thinking about it), anyway it would be graat if I would be able to wite some SQL select with union because of performance (instead of two separate selects). There is no way to make it in that way in hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 1:38 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
There is, but it would require regarding some points as endpoints and others as startpoints. I imagine that that's not ideal.

Or maybe.. here's something I haven't tried, but maybe you can tweak it to work. Map Point twice, using entity-name to distinguish them (entity-name="StartPoint"). I don't know what ramifications this would have (would you have to refer to points where you don't care if they're start or end as start?), but it's possible that this would allow you to have two separate sets of points in your path.

And of course, there's the DB-normalizing solution: remove startPointId and endPointId from the Path table, and create a new PathPoints table with three columns, PathID, PointID, PointType (start or end). This would probably be the one I'd go for, as the resulting queries would be much more efficient even than the unioned version of what you're currently aiming for. Added bonus: if you ever need to extend to have an EnRoute point type.. no problem!

_________________
Code tags are your friend. Know them and use them.


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.