Using Hibernate 3, and am running into a code duplication problem. I've got a couple of concrete classes which all share a common set of scalars defined in a superclass:
MetadataDomainObject (abstract)
createdDate
modifiedDate
I want to keep these scalars defined in each table for performance reasons, but don't want to duplicate code in each .hbm.xml mapping file.
I tried to include XML fragments in the mapping files to bring in these metadata fields, but I am limited in the way that I can bring them in (either a jar, http, or file mapping) -- they don't work in both the development and deployment environment.
For example,
User.hbm.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//END" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" [
<!ENTITY metadata SYSTEM "src/config/hibernate/metadata.fragment">
]>
<hibernate-mapping>
<class name="com.hannonhill.paces.dom.User" table="USERS">
<id name="id" column="id" type="long" unsaved-value="0">
<generator class="native"/>
</id>
&metadata;
</class>
</hibernate-mapping>
This works when running my integration tests from eclipse, because then the "src/config/hibernate/metadata.fragment" relative path resolves correctly. This breaks when I deploy, because there is no "src/config/hibernate" path in my deployed WAR environment. I think that ideally I would be able to use classpath:// as a protocol for defining these external entities -- unfortunately, that protocol is not supported by the default Java 1.5 xerces parser.
Any recommendations on a better way to go about approaching this?
thanks
Collin