Hi,
I have the following problem. Consider Class A and B:
class Identifier
{
long id;
long effectiveFrom;
}
class PO
{
Identifier id;
long effectiveTo;
}
class A extends PO
{
String name;
B b;
}
class B extends PO
{
}
All instances have versions(not talking about the version check for optimistic locking; have deliberately kept that out of this example to avoid confusion).
So for e.g. for an id = 1 there maybe multiple rows in the table A each with a different range for (effectiveTo, effectiveFrom)
Objects have independent lifecyles and hence may version at different times.
In a Session, there is information on which version of any Object is effective. Think of this as the 'as of' date of the Session.
Given this any reference, like the reference from A to B should resolve to the effective version of B.
For e.g. consider an instance of A(id = 1, b= 2, effectiveFrom=0, effectiveTo=10000000)
For b=2 there maybe multiple rows/instances in the system. The resolution to a particular instance is based on the 'as of' Session Context.
My thoughts were that such a custom resolution could be solved by:
- PropertyAccessors; but this doesn't work because I don't have access to a Session in the Getters and Setters
- define a custom UserType. Again I don't have access to the Session.
- I was looking at EntityType. Extending OneToOneType seems a promising path; but it doesn't appear as though I can configure Hibernate to use a subtype of OneToOneType.
Anybody have thoughts/suggestions on this? Resolving based on the effectivity of a version, seems like a common problem.
regards,
Harish Butani.
PS
In case you are wondering about CRUD and Search actions. We don't expose Hibernate directly; but have a Svc layer that exposes CRUD and search actions:
- we add in the necessary conditions for Search and load. Search is only exposed through Criterias
- There is a explicit action to version an Object.
|