• 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

@EmbeddedId with getter/setter ?

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I use something like:



Do I need getter or setter for an EmbeddedID-Field?


Look at my class:



Is that correct? Or should I do this:


[ December 18, 2008: Message edited by: nimo frey ]
 
Ranch Hand
Posts: 84
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Nimo, it depends on how the JPA Implementation access the properties if it is defined to access via a setter/getter then you should add them, otherwise it will access the properties with reflection.

In your example you should add the setter and getter because your composite id it's not generated or you will have to also use reflection to change it's value

Regards,
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay.

I use hibernate and found out, that I do not need to have getter/setter for my EmbeddedID (all works fine).

However, for all my other fields I have getter/setter and annotate the @Column to my getter (instead of field-annotation).


I have a minor question, I do not know, when do I need to instantiate an Object in my Entity-Bean(do I have to? should I?)


=new CompositeID


=new HashSet<Entity>();

[ December 18, 2008: Message edited by: nimo frey ]
 
Angel Taveras
Ranch Hand
Posts: 84
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my particular case i like to instantiate every collection that i want to use inside the entity, but also, you could add a few helper methods too. For instance,


[ December 18, 2008: Message edited by: Angel Taveras ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic