I have been working on a set of domain objects that inherit from an abstract class that needs to have knowledge of the identifier's get and set methods. For example:
Code:
ConcreteClass extends AbstractClass {
int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
AbstractClass {
abstract public int getId();
abstract public void setId(int id);
public function() {
int i = getId();
// uses i to do some calculations.
}
}
<hibernate-mapping package="...">
<class name="ConcreteClass" table="....">
<id name="id" column="id">
<generator class="native"/>
</id>
</class>
</hibernate-mapping>
The issue is that I do not want to map the inheritance tree to the database. I want each concrete class to be mapped individually as a domain object (eg. No sharing of primary keys). Hibernate throws the following error when I try a direct mapping:
Initial SessionFactory creation failed.org.hibernate.MappingException: identifier mapping has wrong number of columns:
Is this possible to do this without using inheritance mapping strategies? I would think that Hibernate would allow me to since the get and set functions are defined as abstract.
Creating a helper object is not an option in this case. The super class needs to know about the getId and setId functions based on some contraints of the framework I am using.
Any help would be greatly appreciated. Thanks.