Changed entities fetch from EAGER to disabled Lazy

This commit is contained in:
2021-03-30 13:01:19 +02:00
parent e7546c41e6
commit d223041cf0
4 changed files with 10 additions and 5 deletions

View File

@@ -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<User>,
var departureDate: String,
var origin: String,

View File

@@ -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<Travel> = 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<Travel> = emptyList()
)

View File

@@ -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)
}
}

View File

@@ -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()