JEE11_Data: Repository methods may not declare more than one of the mutually exclusive annotations: @Find, @Query, @Insert, @Update, @Delete, or @Save.
Description:
Annotations like @Find, @Query, @Insert, @Update, @Delete, and @Save are mutually-exclusive. A given method of a repository interface may have at most one:
- @Find annotation,
- lifecycle annotation, or
- query annotation.
If a method of a repository interface has more than one such annotation, the annotated repository method must raise UnsupportedOperationException every time it is called. Alternatively, a Jakarta Data provider is permitted to reject such a method declaration at compile time.
Additional Diagnostic message:
A query method must not also be annotated with a lifecycle annotation (https://jakarta.ee/specifications/data/1.0/jakarta-data-1.0#:~:text=An%20annotated%20query%20method%20must%20not%20also%20be%20annotated%20with%20a%20lifecycle%20annotation).
Examples:
Invalid example
public interface ProductRepository extends DataRepository<Product, Long> {
@Insert
@Update
void save(Product product);
//Invalid: both @Insert and @Update
}
Valid example
public interface ProductRepository extends DataRepository<Product, Long> {
@Insert
void add(Product product); // Only @Insert
}
Specification:
https://jakarta.ee/specifications/data/1.0/jakarta-data-1.0#:~:text=Annotations%20like%20%40Find,at%20compile%20time.
Type of language feature proposed:
Select all that apply
- [x] diagnostic
- [ ] quick-fix
- [ ] snippet
- [ ] other, please specify: