Hi folks,
I've two Entity (called Price and RentalUnit) with a monodirectional ManyToMany relationship.
Here the code:
Code:
@Entity
public class Price {
@ManyToMany
@JoinTable(name = "price_rental_unit",
joinColumns = {@JoinColumn(name = "price_id") },
inverseJoinColumns = {@JoinColumn(name = "rental_unit_id") }
)
@IndexColumn (name = "index_column")
private List<RentalUnit> rentalUnits;
}
@Entity
public class RentlaUnit {
......
}
I'm writing a DAO method using Criteria Hibernate to retrieve all rentalUnits entities that have the same price.
My method would return a List<RentalUnit> from a join between Price and RentalUnit.
I wrote a Criteria like this:
Code:
DetachedCriteria criteria = DetachedCriteria.forClass(Price.class);
criteria.add(Restrictions.idEq(price.getId()));
criteria.createAlias("rentalUnits", "rentalUnit")
.setProjection(Projections.projectionList().add(Projections.property("rentalUnit.name")));
thus I can retrieve the name of RentalUnit but I would like to retrieve the Entity!
Have you any idea to solve this?
Thanks!