-->
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.  [ 4 posts ] 
Author Message
 Post subject: Using Hibernate without getters and setters
PostPosted: Thu Feb 14, 2008 4:54 pm 
Newbie

Joined: Thu Feb 14, 2008 4:26 pm
Posts: 3
Is it possible to effectively use Hibernate without declaring getter and setter functions?

I have recently moved over from C# .Net programming and find that getter and setter functions add noise to my code. So far my Hibernate entity classes have mostly public mapped fields.

For simple single object session.get(id) operations Hibernate works including dirty tracking, without get/set methods. However where a lazy @ManyToOne association is represented as a Hibernate proxy following a session.get(), I find that public mapped fields do not get populated even after tickling the proxy to perform a DB read by calling getVersion().

Can I do something to persuade the proxy to populate public fields?

The following link might be relevant but as a Hibernate beginner I cannot follow the details.

http://www.jdocs.com/page/AjaxSourceCode?oid=18464


Hibernate-Version: 3.2.0.ga


Top
 Profile  
 
 Post subject: Re: Using Hibernate without getters and setters
PostPosted: Thu Feb 14, 2008 5:18 pm 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
If you set the hibernate-mapping default-access="property", you can access the model class from Hibernate with out declaring getter and setter methods.


Top
 Profile  
 
 Post subject: Re: Using Hibernate without getters and setters
PostPosted: Thu Feb 14, 2008 6:04 pm 
Newbie

Joined: Thu Feb 14, 2008 4:26 pm
Posts: 3
sjhyam wrote:
If you set the hibernate-mapping default-access="property", you can access the model class from Hibernate with out declaring getter and setter methods.

Hmm. After reading your post I re-read some pages in the 2007 Java Persistence book and think you meant access="field"?

All my entity classes dervive from a @MappedSuperclass annotated base class that has an Id declared as:

Code:
   @Id
   @GeneratedValue( strategy=GenerationType.IDENTITY)
   public Integer Id;


I believe this means that Hibernate will access my entities through direct field access.

Anyhow this leaves the original problem that a proxied entity instance does not backfill public mapped fields even after it performs a just-in-time hydration from the database. I am beginning to think this is by design and I will have to retrofit getters and setters into my domain model.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 14, 2008 9:03 pm 
Beginner
Beginner

Joined: Thu Dec 13, 2007 2:32 pm
Posts: 26
right access=field is the mapping for such a thing.
I noticed that in JP with Hibernate too, while reading Many to Many relationship mappings with a join table and a composite primary key with additional fields ... good catch though.

Regards
Vyas Anirudh

_________________
Regards,
Vyas, Anirudh


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