Results 1 to 5 of 5

Thread: getHibernateTemplate().findByCriteria throws

  1. #1
    Join Date
    Sep 2006
    Posts
    2

    Default getHibernateTemplate().findByCriteria throws

    Ok...

    In Oracle, I have a table "A" with field ID of type NUMBER

    In Java, my Obj class has this field type as integer.

    All the methods in HibernateDaoSupport classes I have used work well in Saving, Fetching, Delete ..etc

    getHibernateTemplate().get()
    getHibernateTemplate().saveOrUpdate();
    getHibernateTemplate().delete();

    But when I use getHibernateTemplate().findByCriteria(detachedCrit eria) when doing a findall search I get a

    "HibernateSystemException could not set a field value by reflection setter" it has has a full path to this integer field

    So....how do I fix this issue. Is this a hibernate bug. When I change field type to Long, it works well...but I cannot do so.

  2. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    How does your mapping file look like? Have you specified the type of the field in question as "java.lang.Integer"?

    Regards,
    Andreas

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

    Default

    Quote Originally Posted by sansp View Post
    "HibernateSystemException could not set a field value by reflection setter" it has has a full path to this integer field
    Is it anything to do with blogs.warwick.ac.uk/colinyates/entry/i_hate_hibernate/

    Essentially check that there are no invalid values in the column which is mapped:

    Code:
    select distinct (column_id) from your_table
    remember; hibernate cannot convert null to a primitive....
    Colin Yates
    SpringSource - http://www.springsource.com - Spring Training, Consulting, and Support - "From the Source"
    Please read http://www.springframework.org/documentation
    Co-Author of Expert Spring MVC + Web Flow.

  4. #4
    Join Date
    Sep 2006
    Posts
    2

    Default Thanks....Turned out to few of the interger column field values were null.

    Thank you ....
    As sugessted, It Turned out, few of the interger column field values were null. Any recommendation / suggestions how to resolve it. For testing I updated this field data to value 1, and the API worked well, but unfortunately, in our design, we have to allow null values. Please suggest.

  5. #5
    Join Date
    Jul 2006
    Location
    Philadelphia, PA, USA
    Posts
    341

    Default

    Hi sansp,

    Per standard Java, instance variables are initialized to default values, so your integer fields would be initialized to zero even without regard for Hibernate. If you actually want your properties to be nullable, then you have to make them of Object type, such as Integer. In that case, the instance variables will be initialized to null (which is probably what you want) unless you explicitly set them. You also won't have issues with Hibernate setting your properties with a null value.

    -Arthur Loder

Posting Permissions

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