debuglevel / greeting-microservice

Micronaut microservice template written in Kotlin
The Unlicense
5 stars 2 forks source link

Implement hashcode etc for @Entities #22

Open debuglevel opened 2 years ago

debuglevel commented 2 years ago

Will break you neck sooner or later. e.g. because toSet() creates a hashset which has to get the hash, which will recurse into the (lazy loaded) collections of the Entity - and breaks with some exception:

Unexpected error occurred: failed to lazily initialize a collection of role: de.debuglevel.walkingdinner.backend.organisation.Organisation.dinners, could not initialize proxy - no Session
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: de.debuglevel.walkingdinner.backend.organisation.Organisation.dinners, could not initialize proxy - no Session
...
    at org.hibernate.collection.internal.PersistentSet.hashCode(PersistentSet.java:458)
    at de.debuglevel.walkingdinner.backend.organisation.Organisation.hashCode(Organisation.kt)
    at java.util.HashMap.hash(HashMap.java:339)
    at java.util.HashMap.put(HashMap.java:612)
    at java.util.HashSet.add(HashSet.java:220)
    at kotlin.collections.CollectionsKt___CollectionsKt.toCollection(_Collections.kt:1294)
    at kotlin.collections.CollectionsKt___CollectionsKt.toSet(_Collections.kt:1346)
    at de.debuglevel.walkingdinner.backend.organisation.OrganisationService.getAll(OrganisationService.kt:22)

Also add something to DEVELOPMENT.md