Announcement Announcement Module
Collapse
No announcement yet.
Problem with HIbernate Find Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with HIbernate Find

    I'm confused as to why I'm getting an exception for my find statement.

    The JavaDocs say both these methods are available
    Code:
     List 	find(String queryString, Object value)
              Execute a query for persistent instances, binding one value to a "?"
     List 	find(String queryString, Object[] values)
              Execute a query for persistent instances, binding a number of values to "?"
    This works
    Code:
    		String query = "from DocError as de where de.docID = ?";
    		List c = getHibernateTemplate().find(query, docID);
    This does not
    Code:
    		Object[] params = new Object[] { docId, dateFrom, dateTo };
    		String query = "from DocError as de where de.docID = ? and de.docDate >= ? and de.docDate <= ?";
    		List c = getHibernateTemplate().find(query, params);
    There is something wrong with my parameter mapping that I'm not seeing. Searching came up with nothing. Can anyone offer any insight?

    The Exception
    Code:
    org.springframework.orm.hibernate3.HibernateQueryException: Expected positional parameter count: 3, actual parameters: [[Ljava.lang.Object;@82384a] [from DocError as de where de.docID = ? and de.docDate >= ? and de.docDate <= ?]; nested exception is org.hibernate.QueryException: Expected positional parameter count: 3, actual parameters: [[Ljava.lang.Object;@82384a] [from DocError as de where de.docID = ? and de.docDate >= ? and de.docDate <= ?]
    org.hibernate.QueryException: Expected positional parameter count: 3, actual parameters: [[Ljava.lang.Object;@82384a] [from DocError as de where de.docID = ? and de.docDate >= ? and de.docDate <= ?]
            at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:159)
            at org.hibernate.impl.AbstractQueryImpl.verifyParameters(AbstractQueryImpl.java:118)
            at org.hibernate.impl.QueryImpl.list(QueryImpl.java:70)
            at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:831)
            at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
            at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:822)
            at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:818)

  • #2
    I figured it out, stupid mistake

    Comment


    • #3
      What was the mistake? Maybe others can benefit from knowing what went wrong.

      Regards,
      Andreas

      Comment


      • #4
        The problem was with a method signature. It should have been expecting a Object[] when in fact the method was coded to expect an Object. That is why there is an address in the exception when there should have been acutal values listed.

        Dumb mistake

        Comment

        Working...
        X