Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From a Java EE course test: JPA mapping with annotations mixed with XML. Which has higher priority?

On our Java EE course test we had a question, which I am not sure how to answer:

In JPA, if we map with annotations AND XML, which has a higher priority?

  • Annotations
  • XML
  • Depends on configuration
  • Depends on the particular implementation of the ORM tool being used.
  • None, ORM tool will throw an exception, because XML and annotations must not be combined.

From what I see in Mixing JPA annotations and XML configuration it is probably possible (even though not advisable), but this one is focused on hibernate, so it does not cover the possible answer, that it depends on the ORM tool implementing JPA being used.

Could you provide some insight to this (with sources, if any)?

like image 339
Ev0oD Avatar asked Mar 19 '26 06:03

Ev0oD


1 Answers

XML overrides annotations for JPA. The overriding is at the field/property level.

Section 12.1.2 XML Overriding Rules of the JPA 2.0 (JSR-317) specification:

  • https://jcp.org/aboutJava/communityprocess/final/jsr317/index.html
like image 109
bdoughan Avatar answered Mar 21 '26 20:03

bdoughan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!