-->
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-to-one bidirectional case
PostPosted: Fri Nov 03, 2006 6:25 am 
Beginner
Beginner

Joined: Fri Nov 03, 2006 6:15 am
Posts: 21
Hello,

Im quiet new to hibernate but read everything i found on this topic without success. I actually found different possibilities but would like to know which would be correct in my case.


I have a table A and a table B. Bot have the fields shipref and traffictype. It's a composite id.

Now i have my Detail.hbm.xml which is mapping this 2 fields for a 1:1 join.



Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Nov 2, 2006 2:24:54 PM by Hibernate Tools 3.2.0.beta8 -->
<hibernate-mapping>
   <class name="Shipment">
      <id name="id" column="shipref">
         <generator class="native" />
      </id>
      <many-to-one name="shipmentgeo" column="shipref" unique="true"
         not-null="true" />
   </class>

   <class name="Shipmentgeo">
      <id name="id" column="shipref">
         <generator class="native" />
      </id>
      <one-to-one name="shipment" property-ref="shipmentgeo" />
   </class>
</hibernate-mapping>



I already wrote the POJO's for those two tables. How can i now set in a bean those shipref, traffictype fields and after just do a getDetailInformation(), where i get fields from both tables?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 03, 2006 6:41 am 
Regular
Regular

Joined: Tue Feb 24, 2004 11:42 am
Posts: 56
Could you please be a bit more clearer what you are trying to achieve.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 03, 2006 6:52 am 
Beginner
Beginner

Joined: Fri Nov 03, 2006 6:15 am
Posts: 21
Ok i'll try to simplfy it.


Table A <---> Mapping File <-----> Bean A
Table B <---> Mapping File <-----> Bean A

With this structure i can just make a HQL query on a primary key like.

"a.field1,a.field2,b.field5,b.field6 from A,B where A.shipref=B.shipref"


Now what i need is a bean with the mapping file (i have the mapping already as posted in my previous post) where i build up the relation, so that i can i can just query for other fields without the need of joining the tables as they're mapped in the mapping fiel.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 03, 2006 12:02 pm 
Regular
Regular

Joined: Tue Feb 24, 2004 11:42 am
Posts: 56
Well i take it then they both have the same primary key.But i guess you can always extend it to composite key as well.
Have a look into table per subclass . i guess that might solve your problem.
use joined- subclass

hope this helps if not chase me


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.