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