Hello,
One class, two interfaces and a boatload of implementing classes. Class A is a 1-to-0-or-1 mapping to interface B which potentially has a great many implementing classes. Bimpl has a 1-to-many mapping to interface C, again with potentially many implementing classes.
Using <subclass> and table-per-class-hierarchy seems straightforward, but bulky. I have a factory class capable of creating instances of Bimpl and would prefer to use that. Further, instances of Bimpl are smart enough to create the necessary Cimpl instances, but just need the properties set properly.
I'd like to do something like create a class BMock which also implements B. Map it within A as just:
Code:
<many-to-one name="B" column="bID" class="BMock" unique="true"/>
within class A :
Code:
private B b;
// methods only used by Hibernate. business methods use getB and setB directly.
private B getBMock() { return b; }
private void setBMock(B b) { this.b = BFactory.getB(b); }
which I *think* would be ok, except for the fact that the instance of B that I'm keeping track of is different than that which Hibernate is keeping track of. So hibernate will (?) call setCs(Collection<C> cs) on the wrong object.
so, is there any way to sort of tell Hibernate "I know you gave me *that* object in the setX method, but I want you to use *this* object instead"? Or something like that.
Is there a better way of doing this? Should I just shut up and use <subclass>?
thanks,
-don.
Code: