-->
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.  [ 1 post ] 
Author Message
 Post subject: Interfaces and Implicit Polymorphism
PostPosted: Wed Apr 02, 2008 8:30 am 
Newbie

Joined: Mon Apr 09, 2007 12:25 pm
Posts: 19
Location: Boston, MA
Hibernate version:
3.2.0.cr4

Name and version of the database you are using:
HSQLDB 1.8

This is related to a post made by another user here:
http://forum.hibernate.org/viewtopic.php?t=981404&highlight=

Coding to interfaces, I have the following (a silly example, but the real example's more complex):

Code:
public interface SupportsTermination {

   void setTermDate(Date date);
   Date getTermDate();

}

public class Teacher implements SupportsTermination {
   
   long id;
   String name;
   Date startDate;
   Date endDate;
   
   ...
   
   public void setTermDate(Date date){
      this.endDate = date;
   }
   
   public Date getTermDate(){
      return this.endDate;
   }
}

public class Janitor implements SupportsTermination {
   
   long id;
   String name;
   Date startDate;
   Date endDate;
   
   ...
   
   public void setTermDate(Date date){
      this.endDate = date;
   }
   
   public Date getTermDate(){
      return this.endDate;
   }
}


My mapping for Teacher and Janitor would be:

Code:
<hibernate-mapping default-lazy="false" default-cascade="all">
   <class name="com...Teacher"
      table="teacher" lazy="false">
      <id name="id" column="id" type="long">
         <generator class="sequence">
            <param name="sequence">teacher_seq</param>
         </generator>
      </id>
      <property name="name" column="name" />      
      <property name="startDate" column="start_date"
         type="date" />
      <property name="endDate" column="end_date"
         type="date" />
   </class>
</hibernate-mapping>

<hibernate-mapping default-lazy="false" default-cascade="all">
   <class name="com...Janitor"
      table="janitor" lazy="false">
      <id name="id" column="id" type="long">
         <generator class="sequence">
            <param name="sequence">janitor_seq</param>
         </generator>
      </id>
      <property name="name" column="name" />      
      <property name="startDate" column="start_date"
         type="date" />
      <property name="endDate" column="end_date"
         type="date" />
   </class>
</hibernate-mapping>


The idea being that a termination service would be able to perform terminations for any type that implements TerminationAware.

I initially intended to utilize implicit polymorphism, expecting that the following query might work (I'm using Spring's HibernateTemplate) without any additional mapping:

Code:
List<TerminationAware> terms = this.hibernateTemplate
            .find("from TerminationAware");


But I get the following error message:

Quote:
org.hibernate.hql.ast.QuerySyntaxException: TerminationAware is not mapped [from TerminationAware]


So it seems some mapping is necessary. I've read over this section of the reference manual http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#inheritance-strategies several times, but I'm still unclear on how to map this interface.

Any suggestions would be greatly appreciated!

Thanks,
Leo


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

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.