Post posted one year ago: Success.
The person class corresponds to the user class one by one. The ing relationship is as follows:
View plain
Copy to clipboard
Print
?
- Private
User user;
- @ Onetoone
(Cascade = {cascadetype. All}, mappedby =
"Person"
)
- Public
User getuser (){
- Return
User;
- }
- Private
Person;
- @ Onetoone
()
- @ Joincolumn
(Name =
"Personid"
)
- Public
Person getperson (){
- Return
Person;
- }
I want to query the list of persons that have not been matched with a user from person.
View plain
Copy to clipboard
Print
?
- String hql =
"From person as P where p. User is null"
;
But I didn't implement the desired result. The second half of the hibernate statement output by myeclipse is
View plain
Copy to clipboard
Print
?
- From person person0 _ Where person0 _. ID is not
Null
How is it person0 _. ID?
Is not null. How can I change it to person0 _. ID? How can I write it to implement the functions I want?
Thanks
Maracmo
Answer:
I also encountered this problem today. After studying it, you can use the following statement to find out:
From person as P left join P. User as u where u is null.
By default, Hibernate uses the inner join policy to query Association attributes. Therefore
From person as P where P. User is null statement cannot find the person object with the user attribute being null!