Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@EmbeddedId with getter/setter ?

 
nimo frey
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Angel Taveras
Ranch Hand
Posts: 84
Eclipse IDE Hibernate Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Eclipse IDE Hibernate Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic