-->
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: Precise semantics of constrained="true".
PostPosted: Mon Apr 25, 2005 10:20 am 
Newbie

Joined: Mon Apr 25, 2005 9:18 am
Posts: 3
Hi!

We are doing kind of investigation/functionality testing to determine whether Hibernate is an appropriate tool for our needs. In the course of our tests we've run into problems with one-to-one relationships.

The specific issue we are having is the precise semantical meanings of the constrained="true" option.

The documentation says:
Quote:
specifies that a foreign key constraint on the primary key of the mapped table references the table of the associated class. This option affects the order in which save() and delete() are cascaded, and determines whether the association may be proxied (it is also used by the schema export tool).


This is fine and understandable.

HOWEVER, I'm getting reports from my team that when constrained="true" is used together with "foreign" id generator (as per documentation and desired mapping), then Hibernate ignores changes to the "parent" property of the "child" object. I.e. with the mapping outlined below (and assumming that Contract1 with ContractExtension1 are already saved and committed), the following code will have absolutely no effect on database:
Code:
ContractExtension1.setContract(Contract2); // Attempting to re-parent ContractExtension.


It is as if inverse="true" is implied by the constrained="true".

QUESTION1: Is inverse="true" implied by constrained="true"? Does constrained="true" have any other semantical and/or functional implications?

All things considered, it makes sense for constrained="true" to also imply inverse="true". In this kind of association, re-parenting would mean changing the ID of persistent entity, which is not a good thing (tm). However the documentation makes no mention of this, so I'm wondering whether this is intended this way or is it a problem (either in our code or Hibernate).

QUESTION2: If inverse="true" is indeed implied by constrained="true", then does it mean that there's no way to re-parent "child" entity (i.e. ContractExtension)?

Again, it would make sense if so, but I'd very much like to know for sure whether it is explicitly intended this way.

QUESTION3: Is it possible to map one-to-one relationship as mandatory?

With the given mapping nothing prevents creation of the Contract object without ContractExtension object. This is committed and saved in database without an error (and you can't very well put database constraints to that effect). Of course it is easy to prevent on Java object level, but I'm just wondering if there's mapping that would enforce that constraint?

Hibernate version:
3.0.1

Mapping documents (relevant section):
Contract:
Code:
<class name="Contract">
   <id name="id" column="CONTRACT_PK" type="long" unsaved-value="null">
      <generator class="sequence">
         <param name="sequence">CONTRACT_SEQ</param>
      </generator>
   </id>
   <one-to-one name="extension" cascade="all-delete-orphan"/>
</class>


Contract extension:
Code:
<class name="ContractExtension">
   <id name="id" column="CONTRACTEXTENSION_PK" type="long" unsaved-value="null">
      <generator class="foreign">
         <param name="property">contract</param>
      </generator>
   </id>
   <one-to-one name="contract" constrained="true"/>
</class>


Thanks in advance for your time!

_________________
If you aim for the sky, you are liable to end up on
the tree-top, and that tree-top may be good enough.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 26, 2005 8:18 am 
Newbie

Joined: Mon Apr 25, 2005 9:18 am
Posts: 3
Perhaps anyone can point me to a better place to ask this question?

_________________
If you aim for the sky, you are liable to end up on
the tree-top, and that tree-top may be good enough.


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.