-->
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.  [ 2 posts ] 
Author Message
 Post subject: uni-directional association from JDBC
PostPosted: Wed Nov 25, 2009 10:04 am 
Newbie

Joined: Wed Nov 25, 2009 9:32 am
Posts: 7
Dear All!

I'm new to Hibernate tools, so please be patient.
I am trying to generate POJO classes and mapping files (*.hbm.xml) from JDBC connection (from my DB scheme), but I'm not able to generate uni-directional association between two object.
In my DB, I have two tables, with two ID column, which are primary keys. No foreign key is specified in my DB. I set the foreign key link explicitly in hibernate.reveng.xml, that is:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>

   <table-filter match-catalog="myCat" match-schema="dbo"
      match-name="airplane"  package="my.package"/>
   <table-filter match-catalog="myCat" match-schema="dbo"
      match-name="airplane_online" package="my.package"/>
   
   <table catalog="myCat" schema="dbo" name="airplane_online" class="AirplaneOnlineBase"/>
   <table catalog="myCat" schema="dbo" name="airplane" class="AirplaneBase">
   <column name="ID"/>
      <foreign-key constraint-name="AIRPLANE_AIRPLANE_ONLINE" foreign-table = "Airplane_online">
         <column-ref local-column="ID" foreign-column="ID"/>
         <one-to-one property="AirplaneOnline" />
      </foreign-key>
   </table>
</hibernate-reverse-engineering>


When I generate my POJO classes, I got a reference in both classes (as it's bi-rectional), but I would like to have it uni-directional. I don't have mapping files (I generate them too) where i could set the mapping to be uni-directional.
Also, am I missing something, but a single foreign-key should result in uni-directional association, shouldn't it?

Thanks for all the help in advance,
gmate


Top
 Profile  
 
 Post subject: Re: uni-directional association from JDBC
PostPosted: Mon Dec 07, 2009 6:49 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
I'm not a Hibernate buff myself, but seeing that nobody else has answered yet, I'll take the opportunity to show the limits of my understanding:

Actually, in databases, all links are bidirectional. The link is established by having the same ID field in both "airplane" an "airplane-online", and you can navigate in both directions.

What you want is a unidirectional link on the Java side.
In your case, the backlink doesn't hurt much actually - it's loaded lazily, so until and unless you access it, it won't hit the database. Just ignore it.
You do incur the overhead of having an unused field. Unless the Java object is really, really small (just one or two fields), you won't notice the memory footprint.
There may also be some overhead in the lazy loader because it has to deal with one more field. I don't know how relevant that is.

Of course, displaying the backlink might cause your debugger to access it, which would in turn load the object. But that should not be a problem for one-to-one relationships. (In a many-to-one relationship where a One row is related to a gazillion of Many rows, accidentally loading the backlink will cause loading of that gazillion of rows. That's annoying, so I do think that having unidirectional link would be useful in some cases beyond the one you presented here.)


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