Niranjan Deshpande
,
Ranch Hand
Mar 26, 2009 03:49:31
The primary key of an entity can be annotated on the field, on the getter. Is it 'valid' to annotate the setXXX( ) with the @Id?
@Id
private in id;
Or
@Id
public int getId() { }
@Id
public in setId( ) { } <- I remember having read somewhere that persistence provider ignores this! so this is not invalid, although not used?
Sameer Ali
,
Greenhorn
Mar 26, 2009 04:20:38
The DI is done on setters using annotations but JPA uses getters for annotations.
Joe San
,
Ranch Hand
Mar 26, 2009 04:41:44
In JPA terms, annotating the setters are silently ignored by the container. It should be a good candidate for find bugs when you do so.
Niranjan Deshpande
,
Ranch Hand
Mar 26, 2009 04:52:48
so all the three ways are perfectly valid candidates to be correct answers!
Joe San
,
Ranch Hand
Mar 26, 2009 09:05:09
In JPA terms, it is not valid to annotate on a setter though you will be able to compile and run your code.
Ralph Jaus
,
Ranch Hand
Mar 26, 2009 13:12:31
I agree with Jothi. JPA spec 2.1.1 says:
When property-based access is used, the object/relational mapping annotations for the entity class annotate the getter property accessors. These annotations must not be applied to the setter methods.
Niranjan Deshpande
,
Ranch Hand
Mar 27, 2009 07:15:22
Thanks!
You showed up just in time for the waffles! And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com