Skip to content

Commit

Permalink
Merge pull request #400 from MTES-MCT/jpa-init-infraction-natinf
Browse files Browse the repository at this point in the history
fix(Backend): fix lazy init error on InfractionModel.natinf
  • Loading branch information
lwih authored Oct 31, 2024
2 parents b2e1240 + 961277e commit c721fc6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class InfractionModel(
joinColumns = [JoinColumn(name = "infraction_id")]
)
@Column(name = "natinf_code")
var natinfs: List<String>? = mutableListOf(),
var natinfs: List<String> = mutableListOf(),

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "control_id", referencedColumnName = "id")
@JsonIgnore
var control: ControlModel? = null,
Expand All @@ -50,7 +50,7 @@ class InfractionModel(
targetEntity = InfractionEnvTargetModel::class
)
@JsonIgnore
var target: List<InfractionEnvTargetModel>? = null
var target: List<InfractionEnvTargetModel> = mutableListOf()


) {
Expand All @@ -63,7 +63,7 @@ class InfractionModel(
controlType = ControlType.valueOf(controlType),
infractionType = infractionType?.let { InfractionTypeEnum.valueOf(it) },
observations = observations,
target = target?.map { it.toInfractionEnvTargetEntity() }?.firstOrNull(),
target = target.map { it.toInfractionEnvTargetEntity() }?.firstOrNull(),
natinfs = natinfs
)
}
Expand All @@ -76,7 +76,7 @@ class InfractionModel(
actionId = infraction.actionId,
controlType = infraction.controlType.toString(),
infractionType = infraction.infractionType?.toString(),
natinfs = infraction.natinfs,
natinfs = infraction.natinfs.orEmpty(),
observations = infraction.observations,
target = infraction.target?.let {
listOf(InfractionEnvTargetModel.fromInfractionEnvTargetEntity(it))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class JPAInfractionEnvTargetRepository(
}
}

@Transactional
override fun findByActionIdAndVesselIdentifier(
actionId: String,
vesselIdentifier: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ class JPAInfractionRepository(
}


@Transactional
override fun findAllByActionId(actionId: String): List<InfractionModel> {
return dbRepo.findAllByActionId(actionId = actionId)
}

@Transactional
override fun findById(id: UUID): Optional<InfractionModel> {
return dbRepo.findById(id)
}
Expand Down

0 comments on commit c721fc6

Please sign in to comment.