About Hibernate way to get records when the field is empty to get a blank record of the solution

Source: Internet
Author: User

In Oracle databases, when querying data using Hibernate, especially when querying for data using the View object, some fields are empty when the entire record is not available, because when the XML file and the Pojo (bean) file are generated, Because view does not have a primary key argument, so it generates a Pojo class and a corresponding ID class (primary key Class), and this ID class is all the fields in view, and that Pojo class is a field of this ID class, and when Hibernate gets the record, the primary key class is empty and the record is discarded. So if you use the view's Pojo class to query the data, a field is blank, the entire record is empty, and if all the records have one field blank, the number of records you get is 0.

Workaround:

1, rewrite the ID class and the Pojo class, and put the non-empty fields, such as using the primary key in the original table as the ID class field, the other fields are written in the Pojo class, and provide the Getter/setter method.

2, write the XML file:

Change a non-primary key field to a generic field, for example, one of the following non-primary key fields is modified to:

<composite-id name= "id" class= "com.bl.pojo.ViewBlParseAllScoreId" >

<key-property name= "Subschoolid" type= "Java.lang.Long" >
<column name= "sub_school_id" precision= "a" scale= "0"/>
</key-property>

</composite-id>

After modification

<property name= "Subschoolid" type= "Java.lang.Long" >
<column name= "sub_school_id" precision= "a" scale= "0"/>
</property>

This can be.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.