Announcement Announcement Module
Collapse
No announcement yet.
Query the database views Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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.

    Thanks

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

    Comment


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

      Comment


      • #4
        Hi,
        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.
        <hibernate-mapping>
        <class name="TestVw" table="TEST_VW" mutable="false">
        <composite-id>
        <key-property name="testId" type="java.lang.Long">
        <column name="TEST_ID"/>
        </key-property>
        <key-property name="testName" type="java.lang.String">
        <column name="TEST_NAME"/>
        </key-property>
        <key-property name="Contact" type="java.lang.Integer">
        <column name="CONTACT"/>
        </key-property>
        </composite-id>
        <property name="bodyMassIndex" type="java.lang.Double">
        <column name="BODY_MASS_INDEX"/>
        </property>
        <property name="phone" type="java.lang.String">
        <column name="PHONE"/>
        </property>
        <property name="fax" type="java.lang.String">
        <column name="FAX"/>
        </property>
        <property name="email" type="java.lang.String">
        <column name="EMAIL"/>
        </property>
        <class>
        </hibernate-mapping>

        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!

        Comment

        Working...
        X