Forums Register Login

@Id

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
The DI is done on setters using annotations but JPA uses getters for annotations.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
so all the three ways are perfectly valid candidates to be correct answers!
+Pie Number of slices to send: Send
In JPA terms, it is not valid to annotate on a setter though you will be able to compile and run your code.
+Pie Number of slices to send: Send
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.


+Pie Number of slices to send: Send
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


reply
reply
This thread has been viewed 1080 times.
Similar Threads
Using Oracle sequence with JBOSS
Mapping annotations for variables.
Trouble running example in Hibernate Made Easy, page 95
composite primary keys
JPA strange error.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:43:28.