I am trying to create a generic ID(Integers, Strings, Composites) to be embedded in the tables of respective entities(having their own ID).
I have created a Generic ID interface(GenericPJM_Id) and using specific embeddable ID objects in all my entities. I also have Generic Entity interface(GenericPJM) which has a generic type for ID.
I tried using @OneToOne mapping and then, in turn, using targetEntity as GenericID.class. This doesn’t work as it is @Embeddable
Finally, I tried to define @TypeDefs which is also not working. Error:GenericPJM_Id has no persistent id property:GenericPJM.id.
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@TypeDef(
name = "GenericPJM_Id",
defaultForType = GenericPJM_Id.class,
typeClass = GenericPJM_Id.class
)
public interface GenericPJM<T extends GenericPJM_Id> {
@EmbeddedId
@Type(type="GenericPJM_Id")
T getId();
void setId(T id);
}
@Embeddable
public interface GenericPJM_Id extends Serializable {}
Each entity is supposed to implement Generic Entity and each entity will have its own Embeddable Id(all composites with only one field is fine). All embeddable Ids will implement Generic Id.