Hibernate placeholder? And: And JPA, hibernate occupies jpa

Source: Internet
Author: User

Hibernate placeholder? And: And JPA, hibernate occupies jpa

A summary of hibernate placeholders.

1. What is the most common? Placeholder.

String hql = "select a from Apple a where a. color =? A. weight>? "; Query query = session. createQuery (hql); query. setParameter (0," red "); query. setParameter (1," 10 ");

Subscript starts from 0. The most common problem is the number? Number...

2. placeholder in the form of a variable name.

String hql = "select a from Apple a where. color =: pcolor. weight>: pweight "; Query query = session. createQuery (hql); query. setParameter ("pcolor", "red"); query. setParameter ("pweight", "10 ");

Does this exist? The number is incorrect. It should be a convenient method.

3. JPA method. This method is an improved version of 1 ..

String hql = "select a from Apple a where a. color =? 2 a. weight>? 5 "; Query query = session. createQuery (hql); query. setParameter (" 2 "," red "); query. setParameter (" 5 "," 10 ");

In method 1? The index can be appointed at will ..

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.