I'm implementing Hibernate for the first time, and I have run into a number of problems with the use of interfaces and subclasses which I'm unable to find any particular samples or advice on. I'm using Hibernate 2.1.6 and generating mappings via Hibernatedoclet (xdoclet). Any comments welcome.
I have a simple inheritance structure as follows:
Interfaces:
Company,
BuyingCompany extends Company
SupplierCompany extends Company
Classes:
AbstractCompany implements Company
BuyingCompanyImlp extends AbstractCompany, implements BuyingCompany
SupplierCompanyImpl extends AbstractCompany, implements SupplierCompany
The problems I'm getting are both conceptual and practical.
Firstly, if I try and generate mappings from the interfaces, I get a problem with the hibernate doclet not mapping joined-subclasses for interfaces (ie Company will be generated, but joined-subclass BuyerCompany will not). Regardless of this problem, is it good practice to map interfaces rather than concrete/absract classes ?
If I do the mapping on the classes rather than the interfaces (ie AbstractCompany), I get all kinds of problems when I try and retrieve instances. For example, if I try find("from Company"), I get a Hibernate mapping error. However, I want to try and get instances of Company interface, rather than AbstractCompany or BuyerCompanyImpl.
I hope this makes sense, Grateful for any comments or pointers,
Regards,
_________________ Lawrie Nichols
|