I have following class ( entity )
@Entity
public class Magazine {
private int id ;
private String magazine;
//getters and setters
}
// tracking the magazine arrival
@Entity
public class MagazineIn {
private int id;
private java.util.Date inDate;
private java.util.Date magdate;
@OneToOne
private Magazine mag ;
//getters and setters
}
Now i want to get all arrival status of all magazine , whether
magazine has in or not
using criteria query
following is code
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
Root<MagazineIn> magIn = cq.from(MagazineIn.class);
Join<Magazine,MagazineIn> mag = magIn.join("mag" , JoinType.LEFT);
cq.multiselect(mag.get("magazine") , magIn.get("magdate") ,
magIn.get("inDate"));
TypedQuery<Object[]> q = em.createQuery(cq);
But i am not getting all the magazine listing with indate and magdate null.RIGHT JOIN is not supported. What’s wrong?
If the entity relationships changes are not possible you could consider changing the root of your query to Magazine and use a subquery which correlates on the ‘mag’ variable.