I'm trying to convert my old Hibernate GenericDAO to an EJB3.0 GenericDAO. My problem is that EJB3.0 requires a specific Query to retrieve all objects rather then a Criterion (like Hibernate) that is purely defined by a class type.
Hibernate could do it like this: | protected List<I> | findAll() | throws DAOException | { | List<I> myList; | | try | { | Criteria aCriteria = | getSession().createCriteria(I); | myList = aCriteria.list(); | } | catch(HibernateException anException) | { | throw new DAOException(anException); | } | catch(Exception anException) | { | throw new DAOException(anException); | } | | return myList; | } | My question is: Can the EntityManager (or some other service object) use something other then a query to obtain all objects from a table? | public abstract class | GenericEJBDAO<I, T, ID> | implements GenericDAO<I, ID> | { | //-------------------------------------------------------------------- | // Constructors | //-------------------------------------------------------------------- | | protected GenericEJBDAO(Class<I> aPersistanceInterface, | Class<T> aPersistanceClass) | { | thePersistanceInterface = aPersistanceInterface; | thePersistanceClass = aPersistanceClass; | } | | //-------------------------------------------------------------------- | // Public methods | //-------------------------------------------------------------------- | | public Collection<T> | findAll() | throws DAOException | { | try | { | ...? | } | catch(Exception anException) | { | throw new DAOException(anException); | } | } | | public I | findByID (ID anID) | throws DAOException | { | if(anID == null) | throw new IllegalArgumentException("ID cannot be null"); | | Object myPersistantObject = theManager.find(thePersistanceClass, anID); | return thePersistanceInterface.cast(myPersistantObject); | } | | public void | delete(ID anID) | throws DAOException | { | if(anID == null) | throw new IllegalArgumentException("ID cannot be null"); | | Object myPersistantObject = theManager.find(thePersistanceClass, anID); | theManager.remove(myPersistantObject); | } | | //-------------------------------------------------------------------- | // Members | //-------------------------------------------------------------------- | | @PersistenceContext | protected EntityManager theManager; | | private Class<T> thePersistanceClass; | | private Class<I> thePersistanceInterface; | View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3951664#3951664 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3951664 _______________________________________________ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user