Note the number of decimal places in fields in the Hibernate and Oracle views

Source: Internet
Author: User

SELECT count (expscore) as count, sum (expscore) as sum, max (expscore) as max, min (expscore) as min, round

(Avg (EXPSCORE) * 1000)/1000 as avg, a. EXPACTID, B. teachercode, B. expname, c. classid, a. scoresubmit, a. scoreverify, c. schoolid

FROM expscore a, EXPACTIVATED B, schoolmajorclass c

Where a. expactid = B. expactid and B. schclassid = c. schclassid

Group by a. EXPACTID, B. teachercode, B. expname, c. classid, a. scoresubmit, a. scoreverify, c. schoolid

This is an SQL statement created for a view. The view creation statement is omitted.

When Hibernate's Reverse Engineering is used to automatically generate the Hibernate ing file, two class files are generated because the view does not have a primary key, and one class file is another Id, to use the decimal point and control the digits of the decimal point, I use the following method:

1. When an attempt is created, round (avg (EXPSCORE) * 1000)/1000 as avg is used to control the number of decimal places;

2. Modify the attributes in the generated ***. hbm. xml file, for example

<Key-property name = "avg" type = "java. lang. Long">

<Column name = "AVG" precision = "22" scale = "0"/>

</Key-property>

To:

<Key-property name = "avg" type = "java. lang. Double">

<Column name = "AVG" precision = "22" scale = "3"/>

</Key-property>

3. Modify the class file of the primary key id. The variable declared as Long is automatically generated and changed to the Double type.

4. Do not forget to add the new *. hbm. xml configuration file in Hibernate. cfg. xml.

Related Article

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.