File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -394,6 +394,30 @@ If you are 100% sure that you escaped the value properly and you have no better
394394 </properties >
395395 </rule >
396396
397+ <!-- Jakarta Persistence -->
398+ <rule name =" AvoidListAsEntityRelation"
399+ language=" java"
400+ message=" Use a Set instead of a List in entity relations"
401+ class=" net.sourceforge.pmd.lang.rule.xpath.XPathRule"
402+ externalInfoUrl=" https://www.baeldung.com/spring-jpa-onetomany-list-vs-set#bd-pros-and-cons" >
403+ <description >
404+ `List` allows duplicates while a `Set` does not.
405+ A `Set` also prevents duplicates when the ORM reads multiple identical rows from the database (e.g. when using JOIN).
406+ </description >
407+ <priority >2</priority >
408+ <properties >
409+ <property name =" xpath" >
410+ <value >
411+ <![CDATA[
412+ //ClassDeclaration[pmd-java:hasAnnotation('jakarta.persistence.Entity')]
413+ //FieldDeclaration[pmd-java:hasAnnotation('jakarta.persistence.ManyToMany') or pmd-java:hasAnnotation('jakarta.persistence.OneToMany')]
414+ /ClassType[pmd-java:typeIs('java.util.List')]
415+ ]]>
416+ </value >
417+ </property >
418+ </properties >
419+ </rule >
420+
397421
398422 <!-- Rules from JPinPoint with slight modifications -->
399423 <!-- https://github.com/jborgers/PMD-jPinpoint-rules -->
You can’t perform that action at this time.
0 commit comments