-->
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.  [ 1 post ] 
Author Message
 Post subject: Unwanted constraint
PostPosted: Wed Mar 07, 2007 7:10 pm 
Newbie

Joined: Mon Mar 05, 2007 1:39 am
Posts: 10
Location: Brisbane, Australia
I really love using Hibernate but sometimes I just get so stuck. I'm using a table-per-concrete class type structure and have a class that looks like this:

Code:
   <class name="Subcomp" table="cab_subcomp">
      <id name="id" column="_id" type="integer">
         <generator class="identity" />
      </id>
      <property name="quantity" type="integer" column="_quantity" />
      <many-to-one name="comp" class="Comp" column="_comp" />
      <many-to-one name="category" class="Category" column="_category" fetch="join" not-found="ignore" cascade="none" />
   </class>


My Comp table is the parent.
My Subcomp table is the child.

My Category table is an occassional relationship between some Subcomp records and a Category record. It certianly doesn't happen on every record.

As you can see I have tried defining fetch="join", not-found="ignore" and cascade="none" in the hope that one of these might signify an optional join. However it doesn't work - Hibernate still forces a foreign key constraint from column _category to the _id column of the Category table.

There is nothing defined in the Category table that makes any reference to the Subcomp table, and as such this is only a unidirectional link.

I have searched through endless documentation, forums and websites but found no way of creating an optional relation.

I can only see two options open to me:

1. Is to manage the relationship in my code, that is simply define a property 'category_id' and in my Subcomp table and manually retrieve the Category record when required.

2. Is to manually drop the foreign key constraint - the application works normally following this, however it then becomes an additional step required during installation - and it is certainly not an elegant solution.

Is there a better (more elegant) solution???

Cheers
Murray

_________________
Murray Collingwood
Focus Computing
http://www.focus-computing.com.au


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.