-->
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: Problem about mapping.
PostPosted: Sun Oct 05, 2008 2:56 pm 
Newbie

Joined: Sun Oct 05, 2008 2:45 pm
Posts: 8
Hi,
I have 3 Tables (I will give examples not exact tables but same structure and logic)

Code:
Cars :
   ID  ( Car ID)
   Name

Planes :
   ID ( Plane ID)
   Name

Processes :
   ID ( Process ID )
   Type
   VehicleID


Sample Processes Table Data
Code:
ID     Type      VehicleID
---    -------      ------------
1          1               1       
2          1               2
3          2               1
3          2               2


When type is 1, This is Car and means that VehicleID maps to Cars Table,
When type is 2, This is Plane and means that VehicleID maps to Planes Table.
And So On 3, 4, 5, 6 .. for Additional tables.

How can i map something like that? I can not merge these tables, they all must be separated..

I used to handle this by writing native SQL with some functions, however with JPA i could not figure it out..

Thanks again
Regards.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 05, 2008 8:33 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
The problem with that kind of models, is that you cannot use foreign keys.

A partial solution for that, at least for Hibernate selects, would be to use 2 views and /or subselects on processes, and then perofroming Hibernate mappings on those views/subselects.

This will be only good for selection, though, you will still need a separate mapping to Processes as a whole for insertions.

Make sure to indicate in your mapping of the that the id generator for the views/subselects is "foreign", so that there are no conflicts with the id of Processes.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 3:08 pm 
Newbie

Joined: Sun Oct 05, 2008 2:45 pm
Posts: 8
Can you please give an example about that?


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.