-->
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.  [ 5 posts ] 
Author Message
 Post subject: Question on mapping tag attributes...
PostPosted: Fri Dec 03, 2004 9:25 am 
Newbie

Joined: Fri Dec 03, 2004 8:21 am
Posts: 8
Hibernate version: 2.1.7

I know that this may be very primitive. But I could not find help in the documentation.

For mapping tags such as id, property, etc., one of the attributes is access.

For example:
<property
name="propertyName" (1)
column="column_name" (2)
Hibernate 2.1.6 34
type="typename" (3)
update="true|false" (4)
insert="true|false" (4)
formula="arbitrary SQL expression" (5)
access="field|property|ClassName" (6)
/>


I have following questions on this tag attribute:

Q1. If I set access="field", my guess is that the value is retrieved from the database field. Similarly, if it is set to "property", then hibernate retrieves the value from the class property. Is my understanding correct?

Q2. What is access="ClassName" used for?

Q3. As a designer, when should I use "field", "property", or "ClassName"? How does it impact my code?

Any input in this regard is highly appreciated.

Thanks,

_________________
joshi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 03, 2004 10:16 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
well if you weren't able to find help in the documentation about access let me help you ...

take a look at the reference-doc on page 35 ... end of chapter 5.1.9 - property.

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 03, 2004 10:18 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
access describes how hibernate acesses the data in your persistent classes. It has nothing to do with the DB.


If set to
  1. field: H assumes that your class has a variable with the given name. H accesses it via reflection no matter what visibility it has.
  2. property: H assumes that your class has a get and set method with the given name. H accesses this methods to get/set the values of the persistent classes.
  3. ClassName: H useses the class name you specify to access the property. The class must implement the interface PropertyAccessor.


HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 03, 2004 10:19 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
double shot :-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 6:08 am 
Newbie

Joined: Fri Dec 03, 2004 8:21 am
Posts: 8
Thanks to both of you. I was confused with the term field and property.

As in most cases we will have accessors and mutators for the class attributes, it is most appropriate to use "property" as the access strategy.

Thanks again.

_________________
joshi


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