Reputation: 22017
I have three tables.
LEFT ---------|<- LEFT_RIGHT ->|--------- RIGHT
@Entity
class Left {
// no collection mapping for LeftRight
}
@Entity
class Right {
// no collection mapping for LeftRight
}
@Entity
class LeftRight {
@JoinColumn(name="LEFT_ID")
@ManyToOne
private Left left;
@JoinColumn(name="RIGHT_ID")
@ManyToOne
private Right right;
}
Note that neither Left
nor Right
doesn't have any reference for LeftRight
s.
Is there any way with Criteria-API to selecting from Left
while joining to LeftRight
?
Upvotes: 0
Views: 123
Reputation: 18379
Yes, just use a selection.
CriteriaQuery cq = cb.createQuery();
Root r = cq.from(LeftRight.class);
cq.select(r.get("left"));
cq.where(...);
Query query = em.createQuery(cq);
Upvotes: 0
Reputation: 4844
You could create a criteria query for LeftRight
and use projection to retrieve the left
property:
session.createCriteria(LeftRight.class)
// Add whatever restrictions on Left properties
.createCriteria("left")
.add(Restrictions.like("name", "%something%"))
// Use projection to retrieve the left property
.setProjection(Projections.property("left"));
Upvotes: 1