Results 1 to 5 of 5

Thread: findByNamedQueryAndNamedParam with Date param

  1. #1
    Join Date
    Jun 2005
    Posts
    22

    Default 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. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3
    Join Date
    Jun 2005
    Posts
    22

    Default

    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)
    Parameters:
    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 ?

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

    same problem.

    Where should I be looking ?

  4. #4
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Apparently these features exit only in the hibernate package (http://static.springframework.org/sp...eTemplate.html) not hibernate3.
    I don't know why they were not included but I think you should raise an issue on JIRA.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  5. #5
    Join Date
    Apr 2005
    Location
    Portland, OR
    Posts
    8

    Default

    Here's the answer to a slightly different question that answers _your_ question:
    http://opensource.atlassian.com/proj...rowse/SPR-1159

    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:
    http://www.springframework.org/docs/...m.html#d0e6121

Similar Threads

  1. Replies: 17
    Last Post: Jan 2nd, 2007, 01:43 PM
  2. Date format using JDBC Template
    By macmeureg in forum Data
    Replies: 5
    Last Post: Jun 29th, 2005, 10:18 AM
  3. Replies: 3
    Last Post: Apr 5th, 2005, 09:20 PM
  4. Date Field Validation
    By sherihan in forum EJB
    Replies: 0
    Last Post: Feb 7th, 2005, 04:58 AM
  5. Date Property Editors
    By smv in forum Web
    Replies: 2
    Last Post: Aug 29th, 2004, 01:50 PM

Posting Permissions

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