diff --git a/src/main/kotlin/eu/fosil/okupamicoche/entities/Travel.kt b/src/main/kotlin/eu/fosil/okupamicoche/entities/Travel.kt index ca13fc4..df52a3f 100644 --- a/src/main/kotlin/eu/fosil/okupamicoche/entities/Travel.kt +++ b/src/main/kotlin/eu/fosil/okupamicoche/entities/Travel.kt @@ -1,5 +1,7 @@ package eu.fosil.okupamicoche.entities +import org.hibernate.annotations.LazyCollection +import org.hibernate.annotations.LazyCollectionOption import javax.persistence.* typealias TravelId = Long @@ -8,8 +10,10 @@ typealias TravelId = Long class Travel( @Id @GeneratedValue var id: TravelId? = null, @ManyToOne + @LazyCollection(LazyCollectionOption.FALSE) var driver: User, - @ManyToMany(fetch = FetchType.EAGER) // https://stackoverflow.com/questions/22821695/how-to-fix-hibernate-lazyinitializationexception-failed-to-lazily-initialize-a + @ManyToMany + @LazyCollection(LazyCollectionOption.FALSE) var travelers: MutableList, var departureDate: String, var origin: String, diff --git a/src/main/kotlin/eu/fosil/okupamicoche/entities/User.kt b/src/main/kotlin/eu/fosil/okupamicoche/entities/User.kt index f7e1801..43b8e0a 100644 --- a/src/main/kotlin/eu/fosil/okupamicoche/entities/User.kt +++ b/src/main/kotlin/eu/fosil/okupamicoche/entities/User.kt @@ -1,5 +1,7 @@ package eu.fosil.okupamicoche.entities +import org.hibernate.annotations.LazyCollection +import org.hibernate.annotations.LazyCollectionOption import javax.persistence.* typealias UserId = String @@ -11,8 +13,9 @@ class User( var matrixId: String, var name: String, var email: String? = null, - @OneToMany(mappedBy = "driver", fetch = FetchType.EAGER) // https://stackoverflow.com/questions/22821695/how-to-fix-hibernate-lazyinitializationexception-failed-to-lazily-initialize-a + @OneToMany + @LazyCollection(LazyCollectionOption.FALSE) var travelsAsDriver: List = emptyList(), - @ManyToMany(mappedBy = "travelers", fetch = FetchType.EAGER) // https://stackoverflow.com/questions/22821695/how-to-fix-hibernate-lazyinitializationexception-failed-to-lazily-initialize-a + @ManyToMany@LazyCollection(LazyCollectionOption.FALSE) var travelsAsTraveler: List = emptyList() ) \ No newline at end of file diff --git a/src/main/kotlin/eu/fosil/okupamicoche/spring/controller/PrivateTravelRestController.kt b/src/main/kotlin/eu/fosil/okupamicoche/spring/controller/PrivateTravelRestController.kt index 8ec5245..8596c98 100644 --- a/src/main/kotlin/eu/fosil/okupamicoche/spring/controller/PrivateTravelRestController.kt +++ b/src/main/kotlin/eu/fosil/okupamicoche/spring/controller/PrivateTravelRestController.kt @@ -69,7 +69,6 @@ class PrivateTravelRestController( val userId = authService.currentUser(principal).id val useCase = ListUserTravels(travelRepository) val travels = useCase.listUserTravels(userId).map { t -> TravelDto(t) } - logger.debug { "travels=$travels" } ListDto(useCase.countUserTravels(userId), travels) } } diff --git a/src/main/kotlin/eu/fosil/okupamicoche/spring/services/AuthService.kt b/src/main/kotlin/eu/fosil/okupamicoche/spring/services/AuthService.kt index 5676c63..8d38bfe 100644 --- a/src/main/kotlin/eu/fosil/okupamicoche/spring/services/AuthService.kt +++ b/src/main/kotlin/eu/fosil/okupamicoche/spring/services/AuthService.kt @@ -22,7 +22,6 @@ class AuthService( */ fun currentUser(principal: Principal): UserKeycloak { if (principal is JwtAuthenticationToken) { - logger.debug { "claims=${principal.token.claims}" } return UserKeycloak(principal.token.claims) } throw UserIdNotFoundException()