facebook

Hibernate generate queries in DAO

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #261338 Reply

    robwunderlich
    Participant

    I’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

    #261341 Reply

    Haris Peco
    Member

    Rob,

    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

    #261374 Reply

    robwunderlich
    Participant

    I 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

    #261376 Reply

    Haris Peco
    Member

    Rob,

    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

    #261386 Reply

    robwunderlich
    Participant

    Can I submit this as feature request?

    #261387 Reply

    Haris Peco
    Member

    Of course

    Thanks for your feedback,

    #265994 Reply

    Sudhaker Raj
    Member

    It 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;
            }
        }
    
    #266000 Reply

    Haris Peco
    Member

    Sudhaker,

    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,

Viewing 8 posts - 1 through 8 (of 8 total)
Reply To: Hibernate generate queries in DAO

You must be logged in to post in the forum log in