Re: [perfectjpattern-users] Queries in Jpa dao
Brought to you by:
bravegag
From: Giovanni A. <bra...@gm...> - 2010-12-17 12:07:43
|
Hello Mansour Al Akeel, Please find my answers below. On Dec 17, 2010, at 3:22 AM, Mansour Al Akeel wrote: > How do I use queires in a DAO that extends AbstractJpaManagedBaseDao ? > Judging by the code below, in general you are using it correctly. From the Generic DAO documentation page <http://perfectjpattern.sourceforge.net/dp-genericdao.html> you can see that extending JPA has limited capabilities compared to that of e.g. AbstractHibernateManagedGenericDao. See this example <http://perfectjpattern.sourceforge.net/xref/org/perfectjpattern/jee/integration/dao/jpa/MovieGenericDao.html> here your use-case is more elegantly covered by using the findByExample capability. > For example, AbstractJpaManagedBaseDao prevents accessing entityManager. > So I can not use queries to select of filter some objects. Here's a > code: > You can still do: - super.getSession().createQuery(...) or - super.getSession().createNativeQuery(...) these two methods mirror the JPA functionality, so you should be fine. HTH, Best regards, Giovanni > @Stateless(name = "GeoDao") > public class GeoDaoImpl extends AbstractJpaManagedBaseDao<String, Geo> implements GeoDao { > > public GeoDaoImpl() { > super(Geo.class); > } > > @PersistenceContext(unitName = "myPU") > public void setEntityManager(EntityManager em) { > super.setEntityManager(em); > } > > @Override public Geo getByAbbreviation(String abbreviation) { > IQuery query = getSession().createQuery("select g from Geo g WHERE g.abbreviation= :abbr"); > //HERE I NEED TO SET THE PARAMETERS for abbreviation > List <Geo> res = query.getResultList(); > return res.get(0); > } > } > > > I am using openEJB with openJPA. Can not use spring or hibernate. > Am I missing something ? > > > Thank you in advance > > ------------------------------------------------------------------------------ > Lotusphere 2011 > Register now for Lotusphere 2011 and learn how > to connect the dots, take your collaborative environment > to the next level, and enter the era of Social Business. > http://p.sf.net/sfu/lotusphere-d2d > _______________________________________________ > Perfectjpattern-users mailing list > Per...@li... > https://lists.sourceforge.net/lists/listinfo/perfectjpattern-users |