-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Discriminator value in a base (abstract class)
PostPosted: Fri Nov 14, 2003 8:41 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 14, 2003 8:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
There is no problem with assigning an arbitrary discriminator value to the abstract superclass. But if you absolutely hate it, you could also use discriminator-value="null".

Don't worry about the other message.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 14, 2003 8:52 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Thanks Gavin


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.