-->
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: Constrained="true|false" what does this mean?
PostPosted: Mon Feb 18, 2008 9:44 am 
Newbie

Joined: Tue Jul 24, 2007 2:40 am
Posts: 6
Hi,
I was reading the reference document of hibernate and stuck at this.

Code:
<one-to-one
        name="propertyName"                                          (1)
        class="ClassName"                                            (2)
        cascade="cascade_style"                                      (3)
        constrained="true|false"                                     (4)
        fetch="join|select"                                          (5)
        property-ref="propertyNameFromAssociatedClass"               (6)
        access="field|property|ClassName"                            (7)
        formula="any SQL expression"                                 (8)
        lazy="proxy|no-proxy|false"                                  (9)
        entity-name="EntityName"                                     (10)
        node="element-name|@attribute-name|element/@attribute|."
        embed-xml="true|false"
        foreign-key="foreign_key_name"
/>




Code:
constrained (optional) 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 explanation is itself confounding. What does this mean?


constrained (optional) specifies that a foreign key constraint on the primary key of the mapped table references the table of the associated class.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 18, 2008 10:36 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
my understanding is that constrained = true means that the class that you are referencing in that one-to-one relationship, a record must exist for each entry. So when you read an object in, it will be able to load a proxy for the relationship and when you then go to access it it will be able to run a sql call and read it in from the database.

It allows lazy loading in the case of one-to-one relationships. Where as lazy loading in one-to-one normally does not make sense because Hibernate usually overrides the collection methods with database calls and this isn't really possible in a one-to-one when you simply to a getObject() which is a relationship.

constrained = true is a guarantee to hibernate that the object exists so it doesn't error when it then goes to load it.



edit: Here is an article which probably explains it better

http://www.hibernate.org/162.html

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


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.