Java EE Spring Data JPA (ii)

Source: Internet
Author: User

1.JPQL

A. Definition: Java Persistent Query Language (JPQL) is a portable query language designed to bind SQL syntax and simple query semantics together in an expression of an object-oriented expression language • Queries written in this language are portable and can be compiled into SQL on all major database servers.

B. Statement:

Select  from User where u.userid=?

2. One-to-one (Onetoone)

The A.userinfo class has the user attribute (contains the user_id foreign key)

    @OneToOne    @JoinColumn (name= "user_id")    private user user;

B.user class has UserInfo property

    @OneToOne (mappedby= "user")    // who will maintain the relationship    private UserInfo info;

C.JPQL statements

Select  from User  Left Join where u.userid=?

3. One-to-many (Onetomany)

The A.userinfo class has the user attribute (multiparty)

    @ManyToOne    @JoinColumn (name= "user_id")    private user user;    // One 2 A must have a side to    maintain the relationship

B.user class has list<userinfo> attribute (unilateral)

    @OneToMany (mappedby= "user")    private list<userinfo> infos;

C.JPQL statements

Select  from User  Left Join Fetch where u.userid=?

    

Java EE Spring Data JPA (ii)

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.