Results 1 to 8 of 8

Thread: Docs don't make sense

  1. #1
    Join Date
    Aug 2006
    Posts
    221

    Default Docs don't make sense

    From the Spring 2.0 manual:

    public class ProductDaoImpl extends HibernateDaoSupport implements ProductDao {
    public Collection loadProductsByCategory(String category)
    throws DataAccessException, MyException {
    Session session = getSession(getSessionFactory(), false);
    try {
    List result = session.find(
    "from test.Product product where product.category=?",
    category, Hibernate.STRING);
    if (result == null) {
    throw new MyException("invalid search result");
    }
    return result;
    }
    catch (HibernateException ex) {
    throw convertHibernateAccessException(ex);
    }
    }
    }

    But session doesn't have a find method. What am I missing?

    Can anyone tell me how to create a query similar to the one above?

    Thanks.

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Can you tell us where this is in the reference manual. If you find problems with it you should JIRA them. If you aren't going to do it, let me know and I'll do it.
    http://www.springframework.org/support

    Code:
    public class ProductDaoImpl extends HibernateDaoSupport implements ProductDao {
        public Collection loadProductsByCategory(String category)
            throws MyException {
            
            List result = getHibernateTemplate().find("from test.Product product where product.category=?", category);
            if (result == null) {
                throw new MyException("invalid search result");
            }
            return result;
        }
    }

  3. #3
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    The point of that part of documentation is not how to create queries, but how to get a hold of Hibernate session in different ways.

    Once you have a Hibernate session you can use Hibernate docs to check the details.

    If you don't want to/have to use Hibernate API directly, you can take a look at HibernateTemplate documentation.

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    The examples should work though. I think this modified version of the example should work, this basically does what the HibernateTemplate does under the covers.

    Code:
    public class ProductDaoImpl extends HibernateDaoSupport implements ProductDao {
        public Collection loadProductsByCategory(String category)
            throws DataAccessException, MyException {
            
            try {
                Query queryObject = session.createQuery("from test.Product product where product.category=?");
                queryObject.setString(0, category)
                List result = queryObject.list();
                if (result == null) {
                    throw new MyException("invalid search result");
                }
                return result;
            } 
            catch (HibernateException ex) {
                throw convertHibernateAccessException(ex);
            }
        }
    }
    http://www.springframework.org/docs/...hibernate-daos
    Last edited by karldmoore; Dec 15th, 2006 at 07:12 AM.

  5. #5
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    Yes, it was probably copy&paste error from old Hibernate 2 examples.

  6. #6
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

  7. #7
    Join Date
    Aug 2006
    Posts
    221

    Default Thanks

    Wow! I was just checking back and found that someone else had created the bug for me.

    Thank you very much!

  8. #8
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote Originally Posted by thehl View Post
    Wow! I was just checking back and found that someone else had created the bug for me.
    Thank you very much!
    Thats ok, sometimes people don't respond back so I did it while I remembered.

Posting Permissions

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