I am trying to work out how to do the mappings for two different projects that share some entities. Since they share only a limited subset of mappings, my first idea was to separate these mappings out into a separate jar. I'm using hibernate annotations to do the mappings (so they're in the class files, not separate XML).
Both project A and project B depend on this mappings project, which contains only a couple of hibernate mappings. Project A has no mappings of its own but project B does. Whatever I do this always seems to cause problems since if I don't configure a persistence unit for the mappings project, the mappings are never picked up on. Likewise for project B. If I do configure a persistence unit in the mappings project, project A works, but running a query in project B just gives me (Mapping
happens to be the name of the class):
java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Mapping is not mapped
I believe this is caused by project B having its own persistence unit, and obviously the two are not being merged. I don't really want them to either, I'd prefer to only configure one in project A/B and not the jar they depend on. So is there a way to tell hibernate to scan and map the annotations in a dependency jar and add them to the current persistence unit?