Hi,
I have two classes
Offer and Visibility. There is a 1-1 relation between Offer and visibility
Code:
Offer
@OneToOne(optional = false, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "FK_VisibilityID",nullable=false,updatable=false)
@IndexedEmbedded
public Visibility getVisibility() {
return visibility;
}
Visibility
@OneToOne(mappedBy="visibility")
public Offer getOffer() {
return offer;
}
When I make a selection of offers, Hibernate always executes #records queries against the visibility table. Even when I use fetchmode join in the query. This is not great for performance and I just want Hibernate to retrieve the Offer-visibility pair in one go. I think it actually does but then redundantly retrieves the visibility separately
This are examples of a query with the problem:
Code:
public List<Offer> getOffers(Long[] ids) {
DetachedCriteria dc = DetachedCriteria.forClass(Offer.class);
dc.setFetchMode("visibility", FetchMode.JOIN).add(
Restrictions.in("id", ids));
return getHibernateTemplate().findByCriteria(dc);
}
a HQL one
from Offer o inner join fetch o.visibility
What I will see on these queries is the query being executed and then #records separate queries against the visibility table based on visibilityId. This all happens in the context of the execution of the query
Any ideas?
Kind regards,
Marc