Announcement Announcement Module
Collapse
No announcement yet.
getHibernateTemplate().findByCriteria throws Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    How does your mapping file look like? Have you specified the type of the field in question as "java.lang.Integer"?

    Regards,
    Andreas

    Comment


    • #3
      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....

      Comment


      • #4
        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.

        Comment


        • #5
          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

          Comment

          Working...
          X