I would like to ensure that users of my persistence service are not aware of the POJO implementation classes. I have achieved this by defining my domain model as interfaces and declaring the POJO implementation classes to have default (package) level visibility. The persistence service implementation is in the same package so can access them. No other code can get visibility, e.g. it has to call onto factory classes to instantiate the POJO implementations.
Hibernate Core seems to be happy with this and I see nothing in the EJB3 specs that say you can't do this. It does however fail when using the Hibernate Validator as it's current implementation is not able to call onto the methods of the POJO class. I assume this would be easy to change (as the Hibernate Core obviously can do it), but I thought I'd pause and reflect before requesting such a change.
Does anyone have an opinion or any experience on this approach?
Am I likely to encounter more stumbling blocks?
Would I be better off making the POJOs public and relying on project dependencies to control visibility (although these are more easily circumvented)?
Thanks in advance.
|