Optimize REPORT query performance

Source: Internet
Author: User

When the SELECT statement only selects some attributes of the query persistence class, the query result returned by Hibernate is relational data rather than a persistent object. For example:

From customer C inner join C. Orders O group by C. Age

Select C. ID, C. Name, C. Age, O. ID, O. order_number, O. customer_id from customer C inner join C. Orders O group by C. Age

The preceding two hql query statements correspond to the same SQL statement, so the same data in the database can be queried. The difference is that the former returns

The Order persistence objects are stored in the session cache, and the session will ensure their uniqueness. The latter returns relational data, which does not occupy session cache,

As long as there are no variables in the application to apply the data, the memory they occupy can be recycled by the JVM garbage collector.

 

Therefore, the second method can improve the query performance. As long as the application no longer references the data, the memory they occupy will be released.

 

For the second form, you can define a Javabean to overpack the relational data in the query results, so that the application can still access the query results in an object-oriented way. For example:

 

Select from new customerorder (C. ID, C. Name, C. Age, O. ID, O. order_number, O. customer_id)

From customer C inner join C. Orders O group by C. Age

 

The customerorder class is not a persistence class, and its instance will not be added to the session cache.

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.