keule wrote:
I don't think that your solution is possible. What should Hibernate return when you make a query against the super class? Instances of Customer or instances of Distributor? If you would make a query against Customer and one against Distributor you would suddenly hafe two different objects that mean the same.
I use query by example, so if I would request a Distributor, I'll get that one. That confusement wouldn't be an option in our application.
keule wrote:
I think you should really do it that way: Make Customer and Distributor contain an Relation. If thats not enoug, make an Interface with the Methods of Relation und make Customer and Distributor implement it and return the values of the method of the Relation that they contain.
The reason why we choose Hibernate was that we wanted to program our business logic in the way we felt best and we didn't want our business logic to depend on how we would setup our database.
But I did find a solution. First I add the Relation-object
Code:
session.save(relation);
After that I evict the relation out of the session:
Code:
session.evict(relation);
I manually added a record to the database for the Distributor and the Customer:
Code:
insert into customer values(relationId, ...);
insert into distributor values(relationId, ...);
Then I clear the session, set the relationId, find the customer, set the values and update the object:
Code:
session.clear();
customer.setRelationId(relation.getRelationId);
customerDAO.findByExample(customer); // data access object, a find will probably have the same result
customer.setXXX(xxx);
session.update(customer);