So after discussing this with the dba, they are amenable to adding another table. I've attempted to create a collection of LicensePlates added to a LicensePlateSuspend object.
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.digitaldarwin.hibernate.model">
<class name="LicensePlate" table="LicensePlate">
<composite-id name="id" class="LicensePlate$Id" >
<key-property name="licensePlateSuspendId"/>
<key-property name="licensePlate"/>
</composite-id>
<property name="vin"/>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.digitaldarwin.hibernate.model">
<class name="Event" table="Event">
<id name="id" column="eventId">
<generator class="native">
<param name="sequence">event_eventid_seq</param>
</generator>
</id>
<discriminator column="eventType" type="string"/>
<subclass name="Enforcement" discriminator-value="enforcement">
<join table="Enforcement">
<key column="eventId"/>
<property name="name" column="name"/>
</join>
</subclass>
<subclass name="LicensePlateSuspend" discriminator-value="license plate suspend">
<join table="LicensePlateSuspend">
<key column="licensePlateSuspendId"/>
<set name="licensePlates">
<key>
<column name="licensePlateSuspendId" />
<column name="licensePlate" />
</key>
<one-to-many class="LicensePlate"/>
</set>
</join>
</subclass>
</class>
</hibernate-mapping>
For some reason I get a org.hibernate.MappingException with the above Event.hbm.xml. If I comment out the
Code:
<set name="licensePlates">
<key>
<column name="licensePlateSuspendId" />
<column name="licensePlate" />
</key>
<one-to-many class="LicensePlate"/>
</set>
then it will at least read the file without any errors. I am using the following database:
Code:
create table event (
eventId serial primary key,
eventType text
);
create table enforcement (
eventId integer references event primary key,
name text
);
create table licensePlateSuspend (
licensePlateSuspendId integer references event primary key
);
create table licensePlate (
licensePlateSuspendId integer references licensePlateSuspend,
licensePlate text,
vin text,
primary key(licensePlateSuspendId, licensePlate)
);
Unfortunantly they are unwilling to remove the composite key on licensePlate.
Anyone have any suggestions?