Hi,
I have an entity
Offer with two referenced entities A and B
Code:
@OneToOne(optional = false, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "FK_AID",nullable=false,updatable=false)
@IndexedEmbedded
public A getA() {
return a;
}
@OneToOne(optional = false, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "FK_BID",nullable=false,updatable=false)
@IndexedEmbedded
public B getB() {
return b;
}
When I run the following query, Hibernate executes an extra query for each A and B in stead of just retrieving all data in one go. The extra queries are executed as part of the list() action.
Code:
String qry = "from Offer o "
+ "inner join fetch o.a a "
+ "inner join fetch o.b "
qry += " where a.validFrom <= current_date and a.validUntil >= current_date "
+ "and a.disabled = false and o.active = true "
+ "and a.activated = true ";
Query query = getHibernateTemplate().getSessionFactory()
.getCurrentSession().createQuery(qry);
query.setFirstResult(start);
query.setMaxResults(max);
return query.list();
I don't get why A and B require an extra query since they are supposedly eagerly fetched by specifying inner join fetch.
Any ideas on why this might be happening?
Kind regards,
Marc