I have problem with hibernate entity while working with submodules in playframework.
Normally (in single app without submodules) I've used that code:
package models;
@Entity
public class AppMode {
public static AppMode getCurrentConfigurationEntry() {
return JPA.em().find(AppMode.class, 1L);
}
}
But now I have to tell hibernate entity manager to scan submodules models, cause I'm getting an error:
[IllegalArgumentException: Unknown entity: AppMode]
My model class in submodule is in package:
package models.common;
I've already tried:
return JPA.em().find(models.common.AppMode.class, 1L);
return JPA.em().find(common.models.AppMode.class, 1L);
but I'm getting the same error:
[IllegalArgumentException: Unknown entity: models.common.AppMode]
My question is: How to configure hibernate in play subproject to add submodules models class to classpath at runtime?
I have in both build.sbt files declared libraryDependencies with hibernate.
Should I have persistence.xml file/configuration for each module?
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. Here's a solution with pure Hibernate on JavaSE, no Spring: https://stackoverflow.com/a/41845759/377320
I think that your problem is about JPA configuration. Check this this answer which explains JPA multi-module configuration.
Good luck!
I have to mannually add mapping thought xml persistance file and also using Annotation Mapping: @Entity