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.