Results 1 to 4 of 4

Thread: Query the database views

  1. #1
    Join Date
    Nov 2005
    Posts
    2

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

    Default

    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 ...
    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
    Nov 2005
    Posts
    2

    Red face 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. #4
    Join Date
    Jun 2009
    Posts
    1

    Default

    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!

Posting Permissions

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