-->
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: Synchronization and immutable properties
PostPosted: Fri Sep 22, 2006 6:02 am 
Newbie

Joined: Thu Jun 15, 2006 3:33 pm
Posts: 11
Location: Bristol, England
If I were to have an immutable property of a class, usually it would be set in the constructor(s) and a getter method written which wouldn't have to be synchronized. There'd be no setter.

In hibernate, since setters and getters have to be provided for every persistent property, even if they can be private, does this mean that they have to be synchronized to be thread-safe? I don't know how Hibernate's going to use them.

Regards,

Oliver


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 6:14 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Quote:
In hibernate, since setters and getters have to be provided for every persistent property


Wrong, access="field".


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 1:02 pm 
Newbie

Joined: Thu Jun 15, 2006 3:33 pm
Posts: 11
Location: Bristol, England
OK, but I understand that property access is preferred over field access for good practice and have used this.

Given that, do the getters and setters have to be synchronized? There's no performance problem currently, but I may as well remove synchronization if it's not necessary.

If necessary, I'll just leave it there rather than change to field access.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 9:28 am 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
mmm, well hibernate session is not thread safe and each managed object must attach just to one hibernate session at a time!
http://www.hibernate.org/hib_docs/v3/reference/en/html/transactions.html#transactions-basics

so if your setters are private, there is no need for synchronization.
-------------------
don't forget to credit!

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 23, 2006 11:15 am 
Newbie

Joined: Thu Jun 15, 2006 3:33 pm
Posts: 11
Location: Bristol, England
Sounds reasonable,

Thanks


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.