-->
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: Using Annotations or JPA mappings w/ field , accessor method
PostPosted: Mon Sep 25, 2006 2:34 pm 
Newbie

Joined: Thu Feb 24, 2005 10:09 am
Posts: 11
In Chapter 4 you did a very good job of explaining how to use JPA or custom annotations to augment mapping files to set access levels of fields and methods. What I am trying to understand is why one would do this and to what benefit. I believe I understand the implications pertaining to components but need to understand how this would affect persistence.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 2:48 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I'm not sure what else I could possibly write about this. Maybe read it again? :)


Top
 Profile  
 
 Post subject: Making question more direct
PostPosted: Mon Sep 25, 2006 3:00 pm 
Newbie

Joined: Thu Feb 24, 2005 10:09 am
Posts: 11
If a have a

class foo(
String id;
String name;




)


Is there a benefit to setting field access vs. method access? What I was getting from the book was the annotations controlled hibernate persistence calls foo.getID() vs. foo.Id at time of insert,etc. IF I did not do any additional logic in getters and setters (ie. make sure child and parent objects were set properly see your item and categories explanation) wouldn't it make sense to make all values field access. Or is that your point. Is there anything else happening "under the covers" to take into concideration? Thanks and sorry if this is a dumb question..


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 3:25 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I really don't understand your question.


Top
 Profile  
 
 Post subject: I'll try again
PostPosted: Mon Sep 25, 2006 4:45 pm 
Newbie

Joined: Thu Feb 24, 2005 10:09 am
Posts: 11
@Entity
public class Foo{
@Id @GeneratedValue
private Long id;
private String name;

public Long getId(){

}

public String getName(){


}


}


@Entity
pubic class Bar{
private Long id;
private String name

@Id @GeneratedValue
public Long getId(){

}

public String getName(){

}
}

In Foo all attributes of class will be accessed by Hibernate through Fields.
In Bar Attribute ID will be accessed by Hibernate(?) through getter. But in either case getters and setters exists. Italicized is from book that is the basis of my question. What is benefit/trade-off of one method vs. the other?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 4:58 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Uhm, that you don't need to have the getters and/or setter if you have field access? I mean, it's up to you what you want.


Top
 Profile  
 
 Post subject: thanks
PostPosted: Mon Sep 25, 2006 5:48 pm 
Newbie

Joined: Thu Feb 24, 2005 10:09 am
Posts: 11
Ok that is why I made 2 classes both having getters and setters did not know if it affected HIBERNATE generated code.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 26, 2006 2:16 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Hibernate uses Java reflection, it does not care whether you configure it for field or getter access.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 04, 2006 11:43 am 
Newbie

Joined: Sat Nov 04, 2006 11:37 am
Posts: 2
Location: Vienna
As I know there is a slight difference in efficiency.
For method access Hibernate uses the CGLIB code generation library to generate higly efficient code to access the bean with getter/setter methods.
For field access Hibernate uses reflection to access the field directly what is slighlty slower than using the generated code.


Greetings,
Robert


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 04, 2006 12:37 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This is only true for JDK 1.3, AFAI remember. We already discussed removing the CGLIB reflection optimizier in a future version, because it has no real effect on JDK 1.4 and 5.0.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 04, 2006 1:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
not remove, but we did disable it per default in 3.2 and onwards.

_________________
Max
Don't forget to rate


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.