• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

JPA FIeld access query  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody,

I have started preparing jpa cert and going through pro jpa 2 book.
While going through field access, it says about entity class "all filed must be declared as either protected, package or private.Public fields are disallowed"

But then I ran a sample application making the fields as public and I am able to persist the record. so confused, please can someone clarify.
 
author & internet detective
Posts: 39280
727
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sanjay,
Welcome to CodeRanch!

I suspect this is a case of the JPA provider not implementing that part of the specification. It's not good practice to make the fields public though, so I recommend you don't (even though your provider isn't forbidding it.) If you make it public, other code could make changes without the entity being aware.
 
Sanjay Jha
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne,

Thanks a lot for your reply, I am using hibernate, but is it possible hibernate is not implementing that portion of spec, I am not sure. please could you clarify..
and that's correct that I should not use public, I was just playing around because it was written that public is not allowed but it is still working....
 
Jeanne Boyarsky
author & internet detective
Posts: 39280
727
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sanjay Jha wrote: Thanks a lot for your reply, I am using hibernate, but is it possible hibernate is not implementing that portion of spec, I am not sure. please could you clarify..


Yes. I verified the behavior in Hibernate 3. Changing the instance variables to public still worked.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!