Hi,
In order to finish a uni project I need to create a generic DAO.
I followed the generic DAO design as found in the Manning's book Java persistence with hibernate. en ended up with the following methods.
Code:
findById(ID id, boolean lock)
findAll()
findByExample(T example)
makePersistent(T entity)
makeTransient(T entity)
flush()
clear()
The problem is that these method are not enough for my project, which consist of searching entities, ordering them and paging them. I understand that I can do that by creating a method like
Code:
List<T> find(DetachedCriteria dc)
The problem is that would mean that I expose an hibernate interface to the business layer and I don't want that.
I want to create an interface say MyCriteria and a class say MyCriteriaImpl that would do the same as the DetachedCriteria but would let me change the persistence provider by changing just the implementation. I guess it's possible.
The problem is that I don't have time to write such code.
What I want to know is
if there is a pattern that would let me create the MyCriteria interface, and in the MyCriteriaImpl just call methods of the hibernate criteria api.
Like :
Code:
MyCriteriaImpl mci = new MyCriteriaImpl();
mci.addRestrictionLike(property, String value);
and that would just mean a call to :
Code:
DetachedCriteria dc = new DetachedCriteria();
dc.add(Restrictions.like(property, value)
Thanks