I think Hibernate only scans for JPA Entities inside jar files, and not in classes/ folders for example, or it only scans in the jar with the persistence.xml, or something like that. Instead of trying to bend the Hibernate scanner, I felt it would be easier to scan for entities myself. It is a lot easier than I anticipated.
val entities = mutableListOf<Class<*>>()
AnnotationDetector(object : AnnotationDetector.TypeReporter {
override fun reportTypeAnnotation(annotation: Class<out Annotation>?, className: String?) {
entities.add(Class.forName(className))
}
override fun annotations(): Array<out Class<out Annotation>> = arrayOf(Entity::class.java)
}).detect("com.github")
VaadinOnKotlin.entityManagerFactory = Persistence.createEntityManagerFactory("sample", mapOf(AvailableSettings.LOADED_CLASSES to entities))
I have used the detector which is built-in in the atmosphere jar file; but you can use perhaps https://github.com/rmuller/infomas-asl or others as stated here: Scanning Java annotations at runtime
The full code example is located here: https://github.com/mvysny/vaadin-on-kotlin/blob/master/vok-example-crud/src/test/java/com/github/vok/example/crud/Server.kt
None of the following helped: adding
<exclude-unlisted-classes>false</exclude-unlisted-classes>
to the persistence.xml
file did nothing (according to doc it is ignored in JavaSE anyway); adding
<property name="hibernate.archive.autodetection" value="class, hbm" />
to the persistence.xml
file did nothing (I'm not using hbm anyways). Don't waste your time trying to add those, they won't enable proper auto-scan.