I'd like to enforce that JPA entities w/ child col...
# reflect
e
I'd like to enforce that JPA entities w/ child collections of type
MutableSet
have
orphanRemoval = true
on the
@OneToMany
annotation, but I can't figure out a good way to detect that using reflection. This works, but I don't like using
toString
since that might change. Is there another way that I'm missing that I could use to find all properties that are not an immutable Set?
Copy code
@Test
    fun test() {
        val valid = LotEntity::class.declaredMemberProperties
            .asSequence()
            .filter { it.returnType.isSubtypeOf(Collection::class.starProjectedType) }
            .filterNot { it.returnType.toString().startsWith("kotlin.collections.Set") }
            .mapNotNull { it.javaField?.getAnnotation(OneToMany::class.java) }
            .all { oneToMany -> oneToMany.orphanRemoval }
        println(valid)
    }