-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Generic DAO and Wrapper
PostPosted: Mon Nov 22, 2010 7:59 pm 
Newbie

Joined: Sat Sep 05, 2009 3:24 pm
Posts: 3
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.