Hibernate native SQL queries are bound to POJO or other sets, hibernatepojo

Source: Internet
Author: User

Hibernate native SQL queries are bound to POJO or other sets, hibernatepojo

In addition to hql query, hibernate also supports native SQL query. However, we hope that native SQL queries can be bound to POJO, rather than Object objects, and encoding is required.

Hibernate provides createQuery and createSqlQuery interfaces to support hql queries and SQL queries.

Hql queries can be directly mapped to DO.

SQL query can be mapped to a specified object through query. addScalar (String columnAlias, Type type) and query. setResultTransformer (Transformers. aliasToBean (Entity. class.

ColumnAlias is the field alias and type is the database type provided in hibernate.

You can also use query. setResultTransformer (Transformers. AlIAS_TO_ENTITY_MAP) to place the query results in Map sets or other types of sets.

You can also map SQL queries to DO using query. addEntity.

For complex queries or multi-table queries, see: http://www.cnblogs.com/chenyixue/p/5601285.html

Http://blog.csdn.net/wangshfa/article/details/23543565

 

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.