-->
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.  [ 11 posts ] 
Author Message
 Post subject: Clarification regarding <many-to-one> mapping
PostPosted: Sun Dec 04, 2005 11:12 am 
Newbie

Joined: Sat Dec 03, 2005 8:41 am
Posts: 11
I have a very basic query.
If i am using many-to-one relationship, then in mapping file for the class of many-valued end, why do we have <many-to-one> element. cant we use <property> element and in its "type" attirbute mention the class name of single-valued end. besides <property> element could have included optional "cascade" and "outer-join" attribute.
Pls correct me if am wrong. is there any specific reason for having <many-to-one> element.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 04, 2005 6:23 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Property describes a value column, one whose value is wholly dependent on the relevant's entities DB row. many-to-one tells hibernate that it's an entity mapping, where a whole new row in a (usually different) table describes it.

If you used a property element, the field would not be treated as reference to another entity, it would just be an integer or a string or whatever.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 3:12 pm 
Newbie

Joined: Sat Dec 03, 2005 8:41 am
Posts: 11
In that case in the following link

http://www.hibernate.org/hib_docs/refer ... n-property

There if you see under
5.1.9. property

typename could be:

The class name of a custom type(eg. com.illflow.type.MyCustomType)

What does this mean. i could have hbm.xml file for MyCustomType that could actually have some other table mentioned.

Pls verify my understanding.

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 5:23 pm 
Regular
Regular

Joined: Tue Oct 28, 2003 8:25 am
Posts: 72
Location: Belgium
Think of it this way: custom types must be able to be created only via content of the current table only and of course be saved only in the current table.

An example of custom type would be for instance if you had 3 varchar columns in a table - day, month year - and you'd like to make them available in your entity as a single 'CustomDate' object.

many-to-one is used to map a link to an other entity. That's the way it is.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 5:58 am 
Newbie

Joined: Sat Dec 03, 2005 8:41 am
Posts: 11
hi lorban,

Quote:
"Think of it this way: custom types must be able to be created only via content of the current table only and of course be saved only in the current table."


That is taken care by the <component> element. i.e a user -defined class that is persisted to the same table as the owning entity. I am still not very clear that then what is the use of having use defined class name in the <property> element

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 6:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
to handle custom access to fields...e.g. use field or properties (the defaults provided which you can redefine if you want to - very seldom needed).

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 9:29 am 
Newbie

Joined: Sat Dec 03, 2005 8:41 am
Posts: 11
Hi max,
i am still not very clear on this. could you pls elaborate on what u mentioned or give some pointer . And my second question still remains unanswered.


"If i am using many-to-one relationship, then in mapping file for the class of many-valued end, why do we have <many-to-one> element. cant we use <property> element and in its "type" attirbute mention the class name of single-valued end. besides <property> element could have included optional "cascade" and "outer-join" attribute.
Pls correct me if am wrong. is there any specific reason for having <many-to-one> element. "

Thanks in advance,


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 9:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
many-to-one has different semantics than a property.

if we merged them you would not have DTD validation.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 9:49 am 
Newbie

Joined: Sat Dec 03, 2005 8:41 am
Posts: 11
Thanks for taking out ur valuable time.
So that means it is merely for DTD validations, and not required for anything else. coz as per my understanding, the property that defines it is like any other property, but the type differs. Is this understanding right.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 9:52 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 10:10 am 
Newbie

Joined: Sat Dec 03, 2005 8:41 am
Posts: 11
Thanks


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