I have a model like this
Seizurs => MatCountry => MatCountryI18n
When I try to query the data like so
criteria.
createAlias("matCountry","seizure_country",CriteriaSpecification.INNER_JOIN).
createAlias("seizure_country.matCountryI18ns","seizure_country_translation",CriteriaSpecification.INNER_JOIN).
add(Restrictions.eq("seizure_country_translation.matLanguageCode", "de").
setFetchMode("seizure_country", FetchMode.JOIN).
setFetchMode("seizure_country_translation", FetchMode.JOIN);
and get the data from the DB
开发者_运维问答List<Seizure> seizures = getHibernateTemplate().findByCriteria(criteria);
I would expect that hibernate gives me only those objects (specifically those child objects) that match my given query (where translation.matLanguageCode = de)
But when I access the child objects for MatCountryI18n
logger.info("Seizures: "+seizures.get(0).getMatCountry().getMatCountryI18ns().size());
It gives me back ALL the MatCountryI18n objects that are associated with MatCountry
Please help.
What am I'm doing wrong.
Regards JS
You are asking hibernate to give you all Seizurs that have MatCountry's that have one or more MatCountryI18n's with matLanguageCode == 'de'. Which is exactly what you are getting.
It sounds like you want to only select only the specific MatCountryI18n's with matLanguageCode == 'de'. I would do this by staring your select with a MatCountryI18n's Criteria and fetching the Seizurs though your associations in reverse order as you are doing right now. Either programatically or though a ResultTransformer.
精彩评论