Announcement Announcement Module
No announcement yet.
findByNamedQueryAndNamedParam with Date param Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • findByNamedQueryAndNamedParam with Date param

    Can findByNamedQueryAndNamedParam accomodate a Date parameter ? How does it know which binding method to use, as the Hibernate type could be either timestamp, date, or time ?

    There does not seem to be anywhere to specify the actual type in the findByNameQuery.... methods of HibernateTemplate.

    Does this mean if I have Date parameters that I can not use these methods and instead should just get the session and use the type-specific Hibernate binding methods directly ?

  • #2
    Yes it can accomodate a Date - take a look at the methods; you can specify the type for the paramenter in case Hibernate has problems discovering the type by it's own.


    • #3
      Thanks for your response.

      I'm just not seeing it for some reason. I'm looking at the JavaDocs for Spring's HibernateTemplate.

      findByNamedQueryAndNamedParam(String queryName,
      String[] paramNames,
      Object[] values)
      queryName - the name of a Hibernate query in a mapping file
      paramNames - the names of the parameters
      values - the values of the parameters

      If the type of a value in Object[] is java.util.Date, how will Spring know whether to use the Hibernate Query API setDate, setTime or setTimestamp ? I don't see where I can specify either Hibernate.DATE, Hibernate.TIME or Hibernate.TIMESTAMP as the type of the parameter ?

      applyNamedParameterToQuery(org.hibernate.Query queryObject,
      String paramName,
      Object value)

      same problem.

      Where should I be looking ?


      • #4
        Apparently these features exit only in the hibernate package ( not hibernate3.
        I don't know why they were not included but I think you should raise an issue on JIRA.


        • #5
          Here's the answer to a slightly different question that answers _your_ question:

          I have the same problem querying a DB2 DATE column, and worked around it with a HibernateCallback.

          You have a couple of options. The Spring reference lays it out for you: