Hi
I have the following (simplified) class heirachy which I am (trying to) map.
Code:
public class Account {
private Set queues;
}
public abstract class Queue {
private String name;
private Account account;
}
public class IncomingQueue extends Queue {
private Date dateReceived;
}
public class OutgoingQueue extends Queue {
private Date dateSent;
}
There is a many-to-one relationship between Queue and Account.
Initially I tried mapping the the Queue tables using the following xml mapping file:
Code:
<hibernate-mapping>
<class name="Queue" table="queue">
<id name="id" type="long">
<generator class="native" />
</id>
<discriminator column="type" type="character" />
<property name="name" type="string" unique="true" />
<many-to-one name="account" class="exinet.sms.domain.Account" column="accountId"/>
<subclass name="IncomingQueue" discriminator-value="I">
<property name="dateReceived" type="calendar" />
</subclass>
<subclass name="OutgoingQueue" discriminator-value="O">
<property name="dateSent" type="calendar" />
</subclass>
</class>
</hibernate-mapping>
I get the following error at runtime:
INFO: reflection optimizer disabled for: exinet.sms.domain.Queue, InstantiationError: exinet.sms.domain.Queue
and
net.sf.hibernate.MappingException: multiple or zero characters found parsing string
at net.sf.hibernate.type.CharacterType.stringToObject(CharacterType.java:45)
at net.sf.hibernate.persister.EntityPersister.<init>(EntityPersister.java:693)
.. which I can resolve by assigning an discriminator-value to the base class (Queue). This is however an abstract class and my gut feel is that this should not have a discrimator-value as it is will never be instantiated (and therefore never end up persisted).
I ended up mapping the queues to separate tables. This has the added benefit of allowing me to enforce non-null contraints on a per class basis, but now I have to join tables to return all the instances of Queue.
I just don't seem to be able to close that O-R gap !
Any thoughts ? Have a wondered off the beaten path?
Justin