I wonder how JPA defines to handle following scenario:
Table A: | Table B:
ID FK_B | ID
1 10 | 10
2 null | 12
3 11 |
I want all Table A entries with FK_B NULL or referencing not available Table B entry.
public class A implements Serializable {
@Id
private Long id;
@JoinColumn(name = "FK_B", nullable = true)
@ManyToOne
private B b;
}
public class B implements Serializable {
@Id
private Long id;
}
Is it defined, what happens if I use
SELECT a FROM A a LEFT JOIN a.b WHERE a.b IS NULL
or: (Is this possible?)
SELECT a FROM A a LEFT JOIN B b on (b = a.b) WHERE b IS NULL
What I need is a list containing
A(id = 2)
A(id = 3)
Thanks a lot!
Row #3 in your Table A is illegal by definition; if there’s no
Bwith ID=11 you can’t have that row in tableAfor you’d be violating the foreign key constraint.As far as getting all rows from
AwhereBis null, your first query should work. You can also try:although I’m not 100% sure whether that’s valid JPA QL syntax (it works for Hibernate)