• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

hbm2java - private members ?

 
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to generate private setters/getters for my properties via the hbm2java tool ?

Thanks

Pho
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure for my answer.

access attribute of property tag



The access attribute lets you control how Hibernate will access the property at runtime. By default, Hibernate will call the property get/set pair. If you specify access="field", Hibernate will bypass the get/set pair and access the field directly, using reflection. You may specify your own strategy for property access by naming a class that implements the interface net.sf.hibernate.property.PropertyAccessor.

 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is hbm2java ?

Is it a tool to generate java classes?
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is it possible to generate private setters/getters for my properties



What is use of private setters/getters ? Who will use it?
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pradeep Bhat:
What is hbm2java ?

Is it a tool to generate java classes?



Yes. of course.


Hibernate Extensions. This package includes tools for the following tasks:

Java source generation from a mapping file (aka CodeGenerator, hbm2java)

mapping file generation from compiled Java classes or from Java source with XDoclet markup (aka MapGenerator, class2hbm)

There's actually another utitily living in Hibernate Extensions: ddl2hbm. It is considered deprecated and will no longer be maintained, Middlegen does a better job for the same task.

 
Pho Tek
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Somkiat,

The "access" attribute is to tell Hibernate what PropertyAccessors to use.
hbm2java seems to be able to generate only public setters/getters. I want
these to be private.

Pho
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pho Tek:
Somkiat,

The "access" attribute is to tell Hibernate what PropertyAccessors to use.
hbm2java seems to be able to generate only public setters/getters. I want
these to be private.

Pho



Why you want to do this?
 
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pho Tek:
Is it possible to generate private setters/getters for my properties via the hbm2java tool ?

Thanks

Pho



Yes it is possible using a meta element inside your property. The meta should look as:
<meta attribute="scope-get|scope-set|scope-field">private</meta>.

./pope

PS: I don't know how is Hibernate working after this. But I don't thing it is a good decision to use private getters/setters as their scope is to permit access to the property not to be internally used by the class.
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But I don't thing it is a good decision to use private getters/setters as their scope is to permit access to the property not to be internally used by the class.



If you are using internally within a class then why dont you access fields directly.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pradeep Bhat:


If you are using internally within a class then why dont you access fields directly.



I agree with you...
 
Pho Tek
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want disallow the user of the class from setting nulls to some required properties.

Thus, if I have a mapped property "privateFoo", then I will codegen:

[ September 03, 2004: Message edited by: Pho Tek ]
 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So in fact need some more code generated on your source. The solution you want is not reachable. (for the same field generate 2 methods).

You can do the following trick. Generate the Hibernate POJOs with their natural getters/setters and then extend there overridding the settters.

./pope
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


PS: I don't know how is Hibernate working after this. But I don't thing it is a good decision to use private getters/setters as their scope is to permit access to the property not to be internally used by the class.[/QB]



Hibernate does not "care". If the properties are private it uses reflection-tricks to access the private methods (this of course relies on the right security policies - but in a default Java VM you will not have problems)
 
Good heavens! What have you done! Here, try to fix it with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic