Here's a class called Poc.hbm.xml (which means Point of Contact):
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.apvio.sequim.hibernate">
<!-- Point of Contact (Super class of Email, Phone, Fax, etc.). -->
<class name="Poc" table="POC">
<id name="id" column="ID" type="int">
<generator class="native" />
</id>
<many-to-one name="company" class="com.apvio.sequim.hibernate.Company" column="COMPANY_ID" not-null="true" />
<property name="description" column="DESCRIPTION" type="string" not-null="true">
<meta attribute="use-in-tostring">true</meta>
</property>
<joined-subclass name="Email" table="EMAIL">
<key column="POC_ID" />
<property name="email" column="EMAIL" type="string" not-null="false" />
<property name="permitMarketing" column="PERMIT_MARKETING" type="boolean" not-null="true" />
<joined-subclass name="PrimaryEmail" table="PRIMARY_EMAIL">
<key column="POC_ID" />
<many-to-one name="uniqueCompany" class="com.apvio.sequim.hibernate.Company" column="COMPANY_ID" unique="true" not-null="true" />
</joined-subclass>
</joined-subclass>
<joined-subclass name="Phone" table="PHONE">
<key column="POC_ID" />
<property name="phone" column="PHONE" type="string" not-null="false" />
<property name="permitMarketing" column="PERMIT_MARKETING" type="boolean" not-null="true" />
<joined-subclass name="PrimaryPhone" table="PRIMARY_PHONE">
<key column="POC_ID" />
<many-to-one name="uniqueCompany" class="com.apvio.sequim.hibernate.Company" column="COMPANY_ID" unique="true" not-null="true" />
</joined-subclass>
</joined-subclass>
<joined-subclass name="Fax" table="FAX">
<key column="POC_ID" />
<property name="fax" column="FAX" type="string" not-null="false" />
<property name="permitMarketing" column="PERMIT_MARKETING" type="boolean" not-null="true" />
<joined-subclass name="PrimaryFax" table="PRIMARY_FAX">
<key column="POC_ID" />
<many-to-one name="uniqueCompany" class="com.apvio.sequim.hibernate.Company" column="COMPANY_ID" unique="true" not-null="true" />
</joined-subclass>
</joined-subclass>
<joined-subclass name="Address" table="ADDRESS">
<key column="POC_ID" />
<property name="address1" column="ADDRESS1" type="string" not-null="false" />
<property name="address2" column="ADDRESS2" type="string" not-null="false" />
<property name="city" column="CITY" type="string" not-null="false" />
<property name="state" column="STATE" type="string" not-null="false" />
<property name="zip" column="ZIP" type="string" not-null="false" />
<property name="country" column="COUNTRY" type="string" not-null="false" />
<property name="permitMarketing" column="PERMIT_MARKETING" type="boolean" not-null="true" />
<joined-subclass name="PrimaryAddress" table="PRIMARY_ADDRESS">
<key column="POC_ID" />
<many-to-one name="uniqueCompany" class="com.apvio.sequim.hibernate.Company" column="COMPANY_ID" unique="true" not-null="true" />
</joined-subclass>
</joined-subclass>
<joined-subclass name="Url" table="URL">
<key column="POC_ID" />
<property name="url" column="URL" type="string" not-null="false" />
<joined-subclass name="PrimaryUrl" table="PRIMARY_URL">
<key column="POC_ID" />
<many-to-one name="uniqueCompany" class="com.apvio.sequim.hibernate.Company" column="COMPANY_ID" unique="true" not-null="true" />
</joined-subclass>
</joined-subclass>
</class>
<query name="com.apvio.sequim.hibernate.pocByDescription">
<![CDATA[
from com.apvio.sequim.hibernate.Poc as poc
where upper(poc.description) = upper(:description)
]]>
</query>
</hibernate-mapping>
And here's how I use it in code:
Code:
if ( isEmailPrimary() ) {
email = new PrimaryEmail(getCompanyName() + "'s Primary E-mail Address", company, getEmail(), isEmailSpamable(), company) ;
} else {
email = new Email(getCompanyName() + "'s E-mail Address", company, getEmail(), isEmailSpamable()) ;
}
This works great, except I have to mention "company" twice in the constructor.
Am I just an idiot for trying something as overly complicated as this? Or is there actually a way to let Hibernate know what it is I'm attempting to do here?