First, it will be much easier to have RecordStatus defined like this:
Code:
public class RecordStatus {
private Lookup statusLookup;
private Lookup statusReasonLookup;
}
If you want RecordStatus to have getStatus(), getStatusDescription(), etc. methods, then do that using delegation.
I suggest forgetting about the status/statusReason combination constraint in the mapping, and just have two many-to-one relationships from RecordStatus to Lookup. Then enforce the constraints in business logic. This is the simpler and more maintainable solution.
It is possible to have hibernate do this for you, at least in Hibernate3+. It's a bit involved:
- Create StatusLookupImpl and StatusReasonLookupImpl classes: these won't be directly referenced in your app, just in your mapping. You'll be using the Lookup interface throughout your app (and these classes will implement it).
- Use the <subclass> element to describe StatusLookupImpl and StatusReasonLookupImpl as subclasses of LookupImpl (which also implements the Lookup interface).
- Use the where="" attribute in any classes that refer to Lookup objects (presumably, just the RecordStatus class) specify that a particular set uses just StatusLookupImpls or just StatusReasonLookupImpls.
Like I say, it's a bit involved, and definitely requires more work to maintain, hence the recommendation to enforce that constraint in java code. I use this solution in my own apps, though, and it is quite effective.