-->
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: Spring/Hibernate Inheritance Mapping
PostPosted: Mon Apr 04, 2005 11:15 pm 
Newbie

Joined: Thu Aug 19, 2004 9:48 am
Posts: 4
I am using the spring-framework and hibernate to implement a simple dao pattern for my current project. I created interfaces for all the DAO and PO objects that are being used and mapped these interfaces to the actual implementation using Spring's bean factory.

Therefore when I want a DAO, I get it from the bean factory using the interface name and I get back the actual configured implementation. I then want to use the DAO to get some PO's back using HQL.

What I am unable to do is write my HQL using the PO interface and have it return a concrete implementation. I tried using Inheritance Mapping but it makes me add a discriminator to every table. I simply want the Interface to be translated to the implementation class.

Code:
public interface DbVersion extends PersistentObject
{
  public String getTopic();
  public Integer getMajor();
  public Integer getMinor();
  public Integer getPatch();
}

public class DbVersionImpl extends PersistentObjectImpl
                                        implements DbVersion
{
...Implement DbVersion
}

<hibernate-mapping>
  <class name="DbVersionImpl" table="DB_VERSION">
    <id name="topic" column="TOPIC">
      <generator class="assigned"/>
    </id>

    <property name="major" column="MAJOR"/>
    <property name="minor" column="MINOR"/>
    <property name="patch" column="PATCH"/>
  </class>
</hibernate-mapping>


I would like to use hql to get the PO list using the interface name.
i.e "from DbVersion as dbv order by dbv.topic"

However the hbm file seems to force me to use the name of the implementation class instead of the interface. If I change the class to use the interface and use the subclass to specify the implementation I am closer, but it makes me create a discriminator column.

I am looking for a way to automatically translate the interface to the implementation at runtime. This would allow all my code to use interfaces only. In the example above the DbVersion should get converted to DbVersionImpl to match the hbm file.

Any help would be greatly appreciated.


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.