Announcement Announcement Module
Collapse
No announcement yet.
Declare HibernateException when using Hibernate named query? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Declare HibernateException when using Hibernate named query?

    Hi, I have a DAO class that extends Spring's HibernateDaoSupport.
    Because Spring's support, the data access methods in this DAO class do not have to
    declare any exceptions if I use commands such as

    return getHibernateTemplate().find("from Customer");

    However, I would like to use Hibernate's named query feature. If I use:

    getNamedQuery("example.GetCustomers").list();

    I have to explicitly declare HibernateException in method declarations.

    I am a bit confused. Spring is well-known for its capability of
    translating vendor-specific checked data exceptions into unchecked ones.

    I would like to know whether I did something wrong.

    Any comment is greatly appreicated!

    Pete

  • #2
    Pete,

    You can use HibernateTemplate.execute() with your own HibernateCallback to interact directly with the Session object but still let Spring take care of your error handling.

    Rob

    Comment


    • #3
      Why don't you try:

      Code:
        List l = getHibernateTemplate().findByNamedQuery("example.GetCustomers");

      Comment


      • #4
        thanks for your help. the approach:

        List l = getHibernateTemplate().findByNamedQuery("example.G etCustomers");

        is more elegent and is compatible with Spring's sprit: more application less infrastructure code.

        Spring is GOOD!

        Comment

        Working...
        X