From what I know, this isn't possible, but I'd like to present this use case.
Let's say I have a set of Entities, and I want a sub-set of optional Entities. As it stands now, that's not possible. Any relationship must define all Entity classes within a PU, and there must be a corresponding table. I could two version of the Entity Classes, one with no properties, but that gets dirty.
The above spec design is a problem in use cases where a software system is modularized (ie, a may client only pay for specific components), but all Entity relationships needed to be defined.
What if we had the following JPA extension
@Entity
public class Parent {
@OneToMany(.......)
@OptionalEntity
private List<Child> children;
}
@Entity
public class Child {
@ManyToOne(....)
private Parent parent;
}
So, the @OptionalEntity annotation would instruct JPA to only do a join if the Child entity has been registered with a persistence unit. With this extension, I can model my Entities and respect their relationships, but I don't have to build tables for installations that will not use them.
Thoughts?