I have implemented a modular domain/model library, this is shared among other projects. I would like to define hibernate mapping for domain classes at the library and be able to extend it from the referencing projects, in order to keep information used in one project within itself only. I think the best way to do this would be to define annotated interfaces (with @MappedSuperclass) in the library and implement those in the concrete classes at the referencing project:
Code:
//at the domain library
@MappedSuperclass
public interface MyInterface{
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
}
//at the extending project
@Entity
public class MyClass implements MyInterface{
@Column(name="extension")
private String extension;
}
Unfortunately annotated interfaces still not supported by JPA. This is possible if I use abstract classes instead of interfaces, but this would limitate the model architecture of the projects referencing the library, since java does not support multiple inheritance. Another way I tought of is to put the mapping into hibernate.cfg.xml files, this proprietary configuration allows to do something like:
Code:
<class name="model.MyInterface" table="mytable">
<id name="id" type="int" column="id">
<generator class="native"/>
</id>
<subclass name="model.impl.MyClass" discriminator-value="IMPL" >
... properties / extensions ...
</subclass>
</class>
In this case this configuration would be placed at the library and referenced from the extending project persistence.xml. Then, the extensions would be defined in xml files placed also at the exending project and included into the configuration file at the library.
Is it possible to inlcude the xml files this way ? I tryed using XML ENTITY, but the parser complains that the content is not expected at the line of the include, no matter what the included file contains.
What would be the best way to define extensible database mapping for a modular domain library? Should I use JDO instead (would like to avoid) ?