- This topic has 7 replies, 3 voices, and was last updated 17 years, 10 months ago by Haris Peco.
-
AuthorPosts
-
robwunderlichParticipantI’m trying to include query methods in my generated DAO. In my Users.hbm.xml file I’ve specified a query like:
<query name=”model.Users.findAll”>
<![CDATA[
from Users u
]]>
</query>But no findAll() method is generated in UsersDAO. I can see the query generation code in daohome.vm.
#foreach($queryName in $cfg.namedQueries.keySet())
but a displayof $cfg.namedQueries.keySet().size() shows zero, as if thee are no namedQueries present.Is the generation of queries supported by ME or am I doing somthing wrong?
Thanks,
Rob Wunderlich
Haris PecoMemberRob,
Method findAll is not included in MyEclipse’s DAO.You can add this method with changing the velocity templates.More instructions on how to modify the templates can be found in the Hibernate Quickstart (sec. 5.5)
Regards
robwunderlichParticipantI only used “findAll()” as an example. My specific issue is that *no* named queries (queries defined in query elements in the hbm.cfg file) get generated in the DAO, even though the template seems to have support for it. My question is, does the ME GUI actually set cfg.namedQueries prior to processing the template?
Thanks,
Rob
Haris PecoMemberRob,
Unfortunately not.MyEclipse generate DAO only for entity obejcts when you make Reverse Engineering.Myeclipse don’t use some mapping (cfg.xml) in Reverse Engineering
robwunderlichParticipantCan I submit this as feature request?
Haris PecoMemberOf course
Thanks for your feedback,
Sudhaker RajMemberIt works like charm if we add the followings into BaseHibernateDAO.java
private static final Log log = LogFactory.getLog(BaseHibernateDAO.class); /** * Get all object. * * @return list */ public List findAll() { String className = getClass().getName(); className = className.substring(0, className.length()-3); log.debug("getting All instance with class: " + className); try { List list = getSession().createQuery("from " + className).list(); return list; } catch (RuntimeException re) { log.error("get failed", re); throw re; } }
Haris PecoMemberSudhaker,
You are correct.You can make your BaseDAO class (it have to implement IBaseHibernateDAO interface) and add what you want in this class. You can tell MyEclipse that use this class instead of BaseHibernateDAO and all DAOs will inherit this class.
Thank you for your feedback.
Regards,
-
AuthorPosts