• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPA FIeld access query

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic