Announcement Announcement Module
No announcement yet.
Query the database views Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Query the database views

    Is accessing the database view are same as tables using hibernate3 and springframework ?. I get a null values populated . The hibernate mapping was done using middlegen to generate the mapping file for the Oracle view. Rest was all the same as accesing a table .

    List l = this.getHibernateTemplate().find("from abcView")

    The returned list size was actually the number of records in the view, but all of the individual elements in the returned list are NULL. Appreciate your help.


  • #2
    this is a hb only question - Spring has nothing to do with it. I haven't had such a requirement so I don't know what advice to give except check out the HB reference documentation and forums. Maybe naming strategy or the mapping helps ...


    • #3
      Oracle views in Hibernate

      Thanks Costin,
      I figured out that later and found that if any of the composite keys value for a view is null the records pulled out was also null. Appreciate your response.


      • #4
        You need to use the not-null fields/columns of a view in <composite-id>
        and remaining fields as properties.
        Please see the below example.
        <class name="TestVw" table="TEST_VW" mutable="false">
        <key-property name="testId" type="java.lang.Long">
        <column name="TEST_ID"/>
        <key-property name="testName" type="java.lang.String">
        <column name="TEST_NAME"/>
        <key-property name="Contact" type="java.lang.Integer">
        <column name="CONTACT"/>
        <property name="bodyMassIndex" type="java.lang.Double">
        <column name="BODY_MASS_INDEX"/>
        <property name="phone" type="java.lang.String">
        <column name="PHONE"/>
        <property name="fax" type="java.lang.String">
        <column name="FAX"/>
        <property name="email" type="java.lang.String">
        <column name="EMAIL"/>

        The columns TEST_ID, TEST_NAME, and CONTACT are not nullabe((which can't allow null values to store)) fields in tha TestVw view. So i taken them as composite-id as shown above, remaining fields are are nullable(which can allow null values to store) fields. query for the data by following the above configuration. It should get the data without null. Thanks!