From fa459027f34585be8f79da7c5803160dadcb5e25 Mon Sep 17 00:00:00 2001 From: andre Date: Thu, 30 May 2024 12:28:01 +0200 Subject: [PATCH] [205] Add Rule 205 Tests --- pom.xml | 5 +++ .../java/checks/AvoidUsingFetchTypeLazy.java | 37 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingFetchTypeLazy.java diff --git a/pom.xml b/pom.xml index 8bf9a4d..1f9a5fb 100644 --- a/pom.xml +++ b/pom.xml @@ -30,6 +30,11 @@ spring-beans 5.3.25 + + org.hibernate + hibernate-core + 4.3.9.Final + \ No newline at end of file diff --git a/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingFetchTypeLazy.java b/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingFetchTypeLazy.java new file mode 100644 index 0000000..fefd6bf --- /dev/null +++ b/src/main/java/fr/greencodeinitiative/java/checks/AvoidUsingFetchTypeLazy.java @@ -0,0 +1,37 @@ +package fr.greencodeinitiative.java.checks; + +import javax.persistence.FetchType; +import javax.persistence.ManyToMany; +import javax.persistence.OneToMany; +import java.util.Collection; + +public class AvoidUsingFetchTypeLazy { + @OneToMany(mappedBy = "firstEntity") // Noncompliant + private Collection firstEntities; + + @ManyToMany(mappedBy = "firstEntity1") // Noncompliant + private Collection firstEntities1; + + @OneToMany // Noncompliant + private Collection secondEntities1; + + @ManyToMany // Noncompliant + private Collection secondEntities2; + + @OneToMany(mappedBy = "thirdEntity1", fetch= FetchType.EAGER) // Noncompliant + private Collection thirdEntities1; + + @ManyToMany(mappedBy = "thirdEntity1", fetch= FetchType.EAGER) // Noncompliant + private Collection thirdEntities2; + + @OneToMany(fetch = FetchType.LAZY) // Compliant + private Collection fourthEntities1; + + @ManyToMany(fetch = FetchType.LAZY) // Compliant + private Collection fourthEntities2; + + public static class SomeEntity { + + } + +}