aspose file tools*
The moose likes Object Relational Mapping and the fly likes @EmbeddedId with getter/setter ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "@EmbeddedId with getter/setter ?" Watch "@EmbeddedId with getter/setter ?" New topic
Author

@EmbeddedId with getter/setter ?

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
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

Joined: Nov 13, 2008
Posts: 84

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

Joined: Jun 28, 2008
Posts: 580
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

Joined: Nov 13, 2008
Posts: 84

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
 
subject: @EmbeddedId with getter/setter ?