Results 1 to 4 of 4

Thread: Declare HibernateException when using Hibernate named query?

  1. #1

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    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

  3. #3
    Join Date
    Aug 2004
    Posts
    1,107

    Default

    Why don't you try:

    Code:
      List l = getHibernateTemplate().findByNamedQuery("example.GetCustomers");
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

  4. #4

    Default

    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!

Similar Threads

  1. ERROR: Context initialization failed
    By makhlo in forum Architecture
    Replies: 8
    Last Post: Jul 11th, 2008, 01:41 AM
  2. Problem With Hibernate 3 Named Query
    By duffymo in forum Data
    Replies: 4
    Last Post: May 26th, 2007, 03:25 PM
  3. Hibernate Long Session Per Flow?
    By akw in forum Web Flow
    Replies: 21
    Last Post: Dec 12th, 2005, 08:06 PM
  4. hibernate pagination
    By oliverchua in forum Data
    Replies: 8
    Last Post: Sep 23rd, 2005, 06:06 PM
  5. Replies: 1
    Last Post: Aug 9th, 2005, 02:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •