Hibernate HQL Statement Considerations

Source: Internet
Author: User

There are now entity classes Student and user.

public class student{

Private String ID;

Private Sting classroom;

private user user;

@Id
@GeneratedValue (generator = "Paymentablegenerator")
@GenericGenerator (name = "Paymentablegenerator", strategy = "uuid")
@Column (name = "ID", nullable=false,length=36)
Public String getId () {
return this.id;
}
@ManyToOne (fetch = Fetchtype.eager)
@JoinColumn (name = "USER")
@ForeignKey (name= "null")
Public USER GetUser () {
return user;
}
public void SetUser (user user) {
This.user = user;
}
......

}

public class user{

Private String ID;

private String name;

private String password;

......

}

If you don't use Select Direct "from Student" to find

HQL statement: "From Student where user= ' 123456 '"

Then the where is directly appended with "where user= ' 123456 '" (123456 is the ID of the user table record).

If you want to use select "Select Classroom ..." to find

HQL statement: "Select" Select Classroom,user.name as User from Student where uder.id= ' 123456 ' "

Then the where statement already has the user in select already an object to add. (123456 is the ID of the user table record).

You use a SELECT, then you do not persist with hibernate hql, because you get the result is no longer entity class, get results also can not use list<studet>, became list<object[]> ...

It's hard--it's better to just use SQL to get the results list<object[]>

Hibernate HQL Statement Considerations

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.