Skip to content

Commit c04c93b

Browse files
tech: make all join annotations lazy
1 parent 361a937 commit c04c93b

19 files changed

+496
-589
lines changed

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/ControlPlanSubThemeModel.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
package fr.gouv.cacem.monitorenv.infrastructure.database.model
22

33
import fr.gouv.cacem.monitorenv.domain.entities.controlPlan.ControlPlanSubThemeEntity
4-
import jakarta.persistence.Column
5-
import jakarta.persistence.Entity
6-
import jakarta.persistence.GeneratedValue
7-
import jakarta.persistence.GenerationType
8-
import jakarta.persistence.Id
9-
import jakarta.persistence.JoinColumn
10-
import jakarta.persistence.ManyToOne
11-
import jakarta.persistence.Table
4+
import jakarta.persistence.*
125
import org.hibernate.Hibernate
136
import org.hibernate.annotations.Cache
147
import org.hibernate.annotations.CacheConcurrencyStrategy
@@ -23,7 +16,7 @@ class ControlPlanSubThemeModel(
2316
@GeneratedValue(strategy = GenerationType.IDENTITY)
2417
@Column(name = "id", nullable = false, updatable = false)
2518
val id: Int,
26-
@ManyToOne
19+
@ManyToOne(fetch = FetchType.LAZY)
2720
@JoinColumn(name = "theme_id")
2821
val controlPlanTheme: ControlPlanThemeModel,
2922
@Column(name = "subtheme") val subTheme: String,

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/ControlPlanTagModel.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
package fr.gouv.cacem.monitorenv.infrastructure.database.model
22

33
import fr.gouv.cacem.monitorenv.domain.entities.controlPlan.ControlPlanTagEntity
4-
import jakarta.persistence.Column
5-
import jakarta.persistence.Entity
6-
import jakarta.persistence.GeneratedValue
7-
import jakarta.persistence.GenerationType
8-
import jakarta.persistence.Id
9-
import jakarta.persistence.JoinColumn
10-
import jakarta.persistence.ManyToOne
11-
import jakarta.persistence.Table
4+
import jakarta.persistence.*
125
import org.hibernate.Hibernate
136
import org.hibernate.annotations.Cache
147
import org.hibernate.annotations.CacheConcurrencyStrategy
@@ -23,7 +16,7 @@ class ControlPlanTagModel(
2316
@GeneratedValue(strategy = GenerationType.IDENTITY)
2417
@Column(name = "id", nullable = false, updatable = false)
2518
val id: Int,
26-
@ManyToOne
19+
@ManyToOne(fetch = FetchType.LAZY)
2720
@JoinColumn(name = "theme_id")
2821
val controlPlanTheme: ControlPlanThemeModel,
2922
@Column(name = "tag")

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/ControlUnitContactModel.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@ package fr.gouv.cacem.monitorenv.infrastructure.database.model
33
import com.fasterxml.jackson.annotation.JsonBackReference
44
import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitContactEntity
55
import fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit.dtos.FullControlUnitContactDTO
6-
import jakarta.persistence.Column
7-
import jakarta.persistence.Entity
8-
import jakarta.persistence.GeneratedValue
9-
import jakarta.persistence.GenerationType
10-
import jakarta.persistence.Id
11-
import jakarta.persistence.JoinColumn
12-
import jakarta.persistence.ManyToOne
13-
import jakarta.persistence.Table
6+
import jakarta.persistence.*
147
import org.hibernate.annotations.CreationTimestamp
158
import org.hibernate.annotations.UpdateTimestamp
169
import java.time.Instant
@@ -22,7 +15,7 @@ data class ControlUnitContactModel(
2215
@Column(name = "id", nullable = false, unique = true)
2316
@GeneratedValue(strategy = GenerationType.IDENTITY)
2417
val id: Int? = null,
25-
@ManyToOne
18+
@ManyToOne(fetch = FetchType.LAZY)
2619
@JoinColumn(name = "control_unit_id", nullable = false)
2720
@JsonBackReference
2821
val controlUnit: ControlUnitModel,

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/ControlUnitModel.kt

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,10 @@ import com.fasterxml.jackson.annotation.JsonManagedReference
55
import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitEntity
66
import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.LegacyControlUnitEntity
77
import fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit.dtos.FullControlUnitDTO
8-
import jakarta.persistence.Column
9-
import jakarta.persistence.Entity
10-
import jakarta.persistence.FetchType
11-
import jakarta.persistence.GeneratedValue
12-
import jakarta.persistence.GenerationType
13-
import jakarta.persistence.Id
14-
import jakarta.persistence.JoinColumn
15-
import jakarta.persistence.ManyToOne
16-
import jakarta.persistence.OneToMany
8+
import jakarta.persistence.*
179
import jakarta.persistence.Table
10+
import org.hibernate.annotations.*
1811
import org.hibernate.annotations.Cache
19-
import org.hibernate.annotations.CacheConcurrencyStrategy
20-
import org.hibernate.annotations.CreationTimestamp
21-
import org.hibernate.annotations.Fetch
22-
import org.hibernate.annotations.FetchMode
23-
import org.hibernate.annotations.UpdateTimestamp
2412
import java.time.Instant
2513

2614
@Entity
@@ -33,7 +21,7 @@ data class ControlUnitModel(
3321
@Column(name = "id", nullable = false, unique = true)
3422
@GeneratedValue(strategy = GenerationType.IDENTITY)
3523
val id: Int? = null,
36-
@ManyToOne
24+
@ManyToOne(fetch = FetchType.LAZY)
3725
@JoinColumn(name = "administration_id", nullable = false)
3826
@JsonBackReference
3927
val administration: AdministrationModel,
@@ -42,12 +30,12 @@ data class ControlUnitModel(
4230
@OneToMany(fetch = FetchType.LAZY, mappedBy = "controlUnit")
4331
@JsonManagedReference
4432
@Fetch(FetchMode.SUBSELECT)
45-
val controlUnitContacts: List<ControlUnitContactModel>? = mutableListOf(),
33+
val controlUnitContacts: MutableSet<ControlUnitContactModel>? = LinkedHashSet(),
4634
@OneToMany(fetch = FetchType.LAZY, mappedBy = "controlUnit")
4735
@JsonManagedReference
4836
@Fetch(FetchMode.SUBSELECT)
49-
val controlUnitResources: List<ControlUnitResourceModel>? = mutableListOf(),
50-
@ManyToOne
37+
val controlUnitResources: MutableSet<ControlUnitResourceModel>? = LinkedHashSet(),
38+
@ManyToOne(fetch = FetchType.LAZY)
5139
@JoinColumn(name = "department_area_insee_dep")
5240
@JsonBackReference
5341
val departmentArea: DepartmentAreaModel? = null,
@@ -73,8 +61,8 @@ data class ControlUnitModel(
7361
controlUnit: ControlUnitEntity,
7462
administrationModel: AdministrationModel,
7563
departmentAreaModel: DepartmentAreaModel? = null,
76-
controlUnitContactModels: List<ControlUnitContactModel>? = null,
77-
controlUnitResourceModels: List<ControlUnitResourceModel>? = null,
64+
controlUnitContactModels: MutableSet<ControlUnitContactModel>? = null,
65+
controlUnitResourceModels: MutableSet<ControlUnitResourceModel>? = null,
7866
): ControlUnitModel {
7967
return ControlUnitModel(
8068
id = controlUnit.id,
@@ -127,4 +115,27 @@ data class ControlUnitModel(
127115
override fun toString(): String {
128116
return this::class.simpleName + "(id = $id , administrationId = ${administration.id} , areaNote = $areaNote , departmentAreaInseeCode = ${departmentArea?.inseeCode} , isArchived = $isArchived, name = $name , termsNote = $termsNote)"
129117
}
118+
119+
override fun equals(other: Any?): Boolean {
120+
if (this === other) return true
121+
if (javaClass != other?.javaClass) return false
122+
123+
other as ControlUnitModel
124+
125+
if (id != other.id) return false
126+
if (administration != other.administration) return false
127+
if (areaNote != other.areaNote) return false
128+
if (controlUnitContacts != other.controlUnitContacts) return false
129+
if (controlUnitResources != other.controlUnitResources) return false
130+
if (departmentArea != other.departmentArea) return false
131+
if (isArchived != other.isArchived) return false
132+
if (name != other.name) return false
133+
if (termsNote != other.termsNote) return false
134+
if (createdAtUtc != other.createdAtUtc) return false
135+
if (updatedAtUtc != other.updatedAtUtc) return false
136+
137+
return true
138+
}
139+
140+
override fun hashCode(): Int = javaClass.hashCode()
130141
}

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/ControlUnitResourceModel.kt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,7 @@ import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitResourceE
55
import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.ControlUnitResourceType
66
import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.LegacyControlUnitResourceEntity
77
import fr.gouv.cacem.monitorenv.domain.use_cases.controlUnit.dtos.FullControlUnitResourceDTO
8-
import jakarta.persistence.Column
9-
import jakarta.persistence.Entity
10-
import jakarta.persistence.EnumType
11-
import jakarta.persistence.Enumerated
12-
import jakarta.persistence.GeneratedValue
13-
import jakarta.persistence.GenerationType
14-
import jakarta.persistence.Id
15-
import jakarta.persistence.JoinColumn
16-
import jakarta.persistence.ManyToOne
17-
import jakarta.persistence.Table
8+
import jakarta.persistence.*
189
import org.hibernate.annotations.CreationTimestamp
1910
import org.hibernate.annotations.JdbcType
2011
import org.hibernate.annotations.UpdateTimestamp
@@ -28,7 +19,7 @@ data class ControlUnitResourceModel(
2819
@Column(name = "id", nullable = false, unique = true)
2920
@GeneratedValue(strategy = GenerationType.IDENTITY)
3021
val id: Int? = null,
31-
@ManyToOne
22+
@ManyToOne(fetch = FetchType.LAZY)
3223
@JoinColumn(name = "control_unit_id", nullable = false)
3324
@JsonBackReference
3425
val controlUnit: ControlUnitModel,
@@ -40,7 +31,7 @@ data class ControlUnitResourceModel(
4031
val note: String? = null,
4132
@Column(name = "photo")
4233
val photo: ByteArray? = byteArrayOf(),
43-
@ManyToOne
34+
@ManyToOne(fetch = FetchType.LAZY)
4435
@JoinColumn(name = "base_id", nullable = false)
4536
@JsonBackReference
4637
val station: StationModel,

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/DashboardDatasModel.kt

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
11
package fr.gouv.cacem.monitorenv.infrastructure.database.model
22

33
import fr.gouv.cacem.monitorenv.infrastructure.database.model.reportings.ReportingModel
4-
import jakarta.persistence.Column
5-
import jakarta.persistence.Entity
6-
import jakarta.persistence.FetchType
7-
import jakarta.persistence.GeneratedValue
8-
import jakarta.persistence.GenerationType
9-
import jakarta.persistence.Id
10-
import jakarta.persistence.JoinColumn
11-
import jakarta.persistence.ManyToOne
12-
import jakarta.persistence.OneToOne
13-
import jakarta.persistence.Table
14-
import java.util.UUID
4+
import jakarta.persistence.*
5+
import java.util.*
156

167
@Entity
178
@Table(name = "dashboard_datas")
@@ -23,19 +14,19 @@ data class DashboardDatasModel(
2314
@ManyToOne(fetch = FetchType.LAZY, optional = false)
2415
@JoinColumn(name = "dashboard_id")
2516
var dashboard: DashboardModel?,
26-
@OneToOne
17+
@OneToOne(fetch = FetchType.LAZY)
2718
@JoinColumn(name = "amp_cacem_id")
2819
val amp: AMPModel?,
2920
@OneToOne
3021
@JoinColumn(name = "reportings_id")
3122
val reportingModel: ReportingModel?,
32-
@OneToOne
23+
@OneToOne(fetch = FetchType.LAZY)
3324
@JoinColumn(name = "vigilance_area_id")
3425
val vigilanceAreaModel: VigilanceAreaModel?,
35-
@OneToOne
26+
@OneToOne(fetch = FetchType.LAZY)
3627
@JoinColumn(name = "regulations_cacem_id")
3728
val regulatoryAreaModel: RegulatoryAreaModel?,
38-
@OneToOne
29+
@OneToOne(fetch = FetchType.LAZY)
3930
@JoinColumn(name = "control_unit_id")
4031
val controlUnitModel: ControlUnitModel?,
4132
@Column(name = "insee_code")

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/EnvActionsControlPlanSubThemeModel.kt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
package fr.gouv.cacem.monitorenv.infrastructure.database.model
22

3-
import jakarta.persistence.Column
4-
import jakarta.persistence.Embeddable
5-
import jakarta.persistence.EmbeddedId
6-
import jakarta.persistence.Entity
7-
import jakarta.persistence.JoinColumn
8-
import jakarta.persistence.ManyToOne
9-
import jakarta.persistence.MapsId
10-
import jakarta.persistence.Table
3+
import jakarta.persistence.*
114
import org.hibernate.Hibernate
125
import java.io.Serializable
13-
import java.util.UUID
6+
import java.util.*
147

158
@Entity
169
@Table(name = "env_actions_control_plan_sub_themes")
1710
class EnvActionsControlPlanSubThemeModel(
1811
@EmbeddedId
1912
val id: EnvActionsSubThemePk,
20-
@ManyToOne
13+
@ManyToOne(fetch = FetchType.LAZY)
2114
@MapsId("envActionId")
2215
@JoinColumn(name = "env_action_id")
2316
val envAction: EnvActionModel? = null,
24-
@ManyToOne
17+
@ManyToOne(fetch = FetchType.LAZY)
2518
@MapsId("subthemeId")
2619
@JoinColumn(name = "subtheme_id")
2720
val controlPlanSubTheme: ControlPlanSubThemeModel? = null,

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/EnvActionsControlPlanTagModel.kt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
package fr.gouv.cacem.monitorenv.infrastructure.database.model
22

3-
import jakarta.persistence.Column
4-
import jakarta.persistence.Embeddable
5-
import jakarta.persistence.EmbeddedId
6-
import jakarta.persistence.Entity
7-
import jakarta.persistence.JoinColumn
8-
import jakarta.persistence.ManyToOne
9-
import jakarta.persistence.MapsId
10-
import jakarta.persistence.Table
3+
import jakarta.persistence.*
114
import org.hibernate.Hibernate
125
import java.io.Serializable
13-
import java.util.UUID
6+
import java.util.*
147

158
@Entity
169
@Table(name = "env_actions_control_plan_tags")
1710
class EnvActionsControlPlanTagModel(
1811
@EmbeddedId
1912
val id: EnvActionsTagPk,
20-
@ManyToOne
13+
@ManyToOne(fetch = FetchType.LAZY)
2114
@MapsId("envActionId")
2215
@JoinColumn(name = "env_action_id")
2316
val envAction: EnvActionModel? = null,
24-
@ManyToOne
17+
@ManyToOne(fetch = FetchType.LAZY)
2518
@MapsId("tagId")
2619
@JoinColumn(name = "tag_id")
2720
val controlPlanTag: ControlPlanTagModel? = null,

backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/EnvActionsControlPlanThemeModel.kt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
package fr.gouv.cacem.monitorenv.infrastructure.database.model
22

3-
import jakarta.persistence.Column
4-
import jakarta.persistence.Embeddable
5-
import jakarta.persistence.EmbeddedId
6-
import jakarta.persistence.Entity
7-
import jakarta.persistence.JoinColumn
8-
import jakarta.persistence.ManyToOne
9-
import jakarta.persistence.MapsId
10-
import jakarta.persistence.Table
3+
import jakarta.persistence.*
114
import org.hibernate.Hibernate
125
import java.io.Serializable
13-
import java.util.UUID
6+
import java.util.*
147

158
@Entity
169
@Table(name = "env_actions_control_plan_themes")
1710
class EnvActionsControlPlanThemeModel(
1811
@EmbeddedId
1912
val id: EnvActionsThemePk,
20-
@ManyToOne
13+
@ManyToOne(fetch = FetchType.LAZY)
2114
@MapsId("envActionId")
2215
@JoinColumn(name = "env_action_id")
2316
val envAction: EnvActionModel? = null,
24-
@ManyToOne
17+
@ManyToOne(fetch = FetchType.LAZY)
2518
@MapsId("themeId")
2619
@JoinColumn(name = "theme_id")
2720
val controlPlanTheme: ControlPlanThemeModel? = null,
Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
package fr.gouv.cacem.monitorenv.infrastructure.database.model
22

33
import fr.gouv.cacem.monitorenv.domain.entities.controlUnit.LegacyControlUnitResourceEntity
4-
import jakarta.persistence.Column
5-
import jakarta.persistence.Entity
6-
import jakarta.persistence.GeneratedValue
7-
import jakarta.persistence.GenerationType
8-
import jakarta.persistence.Id
9-
import jakarta.persistence.JoinColumn
10-
import jakarta.persistence.ManyToOne
11-
import jakarta.persistence.Table
4+
import jakarta.persistence.*
125

136
@Entity
147
@Table(name = "missions_control_resources")
@@ -17,10 +10,10 @@ data class MissionControlResourceModel(
1710
@GeneratedValue(strategy = GenerationType.IDENTITY)
1811
@Column(name = "id")
1912
val id: Int? = null,
20-
@ManyToOne(optional = false)
13+
@ManyToOne(fetch = FetchType.LAZY, optional = false)
2114
@JoinColumn(name = "mission_id")
2215
val mission: MissionModel,
23-
@ManyToOne(optional = false)
16+
@ManyToOne(fetch = FetchType.LAZY, optional = false)
2417
@JoinColumn(name = "control_resource_id")
2518
var resource: ControlUnitResourceModel,
2619
) {
@@ -31,4 +24,24 @@ data class MissionControlResourceModel(
3124
name = resource.name,
3225
)
3326
}
27+
28+
override fun equals(other: Any?): Boolean {
29+
if (this === other) return true
30+
if (javaClass != other?.javaClass) return false
31+
32+
other as MissionControlResourceModel
33+
34+
if (id != other.id) return false
35+
if (mission != other.mission) return false
36+
if (resource != other.resource) return false
37+
38+
return true
39+
}
40+
41+
override fun hashCode(): Int {
42+
var result = id ?: 0
43+
result = 31 * result + mission.hashCode()
44+
result = 31 * result + resource.hashCode()
45+
return result
46+
}
3447
}

0 commit comments

Comments
 (0)