This is the scenario:
I have 2 classes mapped with hibernate: "Foo" and "EnhancedFoo"
both classes are mapped to the same table "foo"
EnhancedFoo extends Foo
Foo.hbm.xml contains a named query "find active foos" which goes like this:
from Foo foo where foo.active = true
Now, if I try to load the configuration I get this exception:
could not resolve property: active of: EnhancedFoo [
from EnhancedFoo foo where foo.active = true
]
which is kind of correct since in EnhancedFoo.hbm.xml there isn't a mapped property "active", but then why is hibernate replacing "Foo" with "EnhancedFoo"?
This is what I've tried:
tried to add a "enity-name" attribute on the mapping files like so:
<class name="myproject.data.entity.Foo" table="foo" entity-name="Foo">
.......
<class name="myproject.data.entity.EnhancedFoo" table="foo" entity-name="EnhancedFoo">
and then configuration loads fine, but whenever I try to insert a Foo I get this:
org.hibernate.MappingException: Unknown entity: myproject.data.entity.Foo
These are the relevant parts of code:
//Foo.java
public class Foo
{
private long id;
private boolean active;
// getters and setters
}
//EnhancedFoo.java
public class EnhancedFoo extends Foo
{
private String extraProperty
// getter and setter
}
//Foo.hbm.xml
//.....
<class name="myproject.data.entity.Foo" table="foo" entity-name="Foo">
<id column="id" name="id">
<generator class="assigned"/>
</id>
<property name="active" column="active" />
</class>
<query name="find_active_foos">
<![CDATA[
from Foo foo where foo.active = true
]]>
</query>
//EnhancedFoo.hbm.xml
//.....
<class name="myproject.data.entity.EnhancedFoo" table="foo" entity-name="EnhancedFoo">
<id column="id" name="id">
<generator class="assigned"/>
</id>
</class>