Hi,

because EJB is implemented via Hibernate in the Background you can try this:


  | public abstract class GenericDAOImpl<T, ID extends Serializable> implements
  |             GenericDAO<T, ID> {
  | 
  |     private static final Log _log = LogFactory.getLog(GenericDAOImpl.class);
  | 
  |     @PersistenceContext(type = PersistenceContextType.EXTENDED, unitName = 
"portalEM")
  |     protected EntityManager em;
  | 
  |     private Class persistentClass;
  | 
  |     public GenericDAOImpl(Class persistentClass) {
  |             this.persistentClass = persistentClass;
  |     }
  | 
  |     public Class getPersistentClass() {
  |             return persistentClass;
  |     }
  | 
  |     @SuppressWarnings("unchecked")
  |     @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
  |     public T findByPrimaryKey(ID id) {
  |             try {
  |                     return (T) em.find(getPersistentClass(), id);
  |             } catch (RuntimeException e) {
  |                     _log.error("Exception while findByPrimaryKey", e);
  |                     throw e;
  |             }
  |     }
  | 
  |     @SuppressWarnings("unchecked")
  |     @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
  |     public List<T> findAll() {
  |             try {
  |                     return em.createQuery("from " + getPersistentClass())
  |                                     .getResultList();
  |             } catch (RuntimeException e) {
  |                     _log.error("Exception while findAll", e);
  |                     throw e;
  |             }
  |     }
  | 
  |     @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
  |     public T makePersistent(T entity) {
  |             try {
  |                     return em.merge(entity);
  |             } catch (RuntimeException e) {
  |                     _log.error("Exception while makeTransient", e);
  |                     throw e;
  |             }
  |     }
  | 
  |     @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
  |     public void makeTransient(T entity) {
  |             try {
  |                     em.remove(entity);
  |             } catch (RuntimeException e) {
  |                     _log.error("Exception while makeTransient", e);
  |                     throw e;
  |             }
  |     }
  | 
  |     @SuppressWarnings("unchecked")
  |     @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
  |     public List<T> findByCriteria(
  |                     org.hibernate.criterion.Criterion... criterion) {
  | 
  |             try {
  | 
  |                     org.hibernate.Session session = 
((org.jboss.ejb3.entity.HibernateSession) em)
  |                                     .getHibernateSession();
  |                     org.hibernate.Criteria crit = session
  |                                     .createCriteria(getPersistentClass());
  | 
  |                     for (org.hibernate.criterion.Criterion c : criterion) {
  |                             crit.add(c);
  |                     }
  | 
  |                     return crit.list();
  | 
  |             } catch (RuntimeException e) {
  |                     _log.error("Exception while findByCriteria", e);
  |                     throw e;
  |             }
  |     }
  | 
  |     @Remove
  |     public void remove() {
  |     }
  | 
  | }
  | 

Because this is not defined in EJB-Spec. don't try on other App-Server.
EJB Spec. doesn't define something like a Criteria-API

Regards

Peter

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3951797#3951797

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3951797


_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to