java - HQL inner join query exlude objects in ManyToOne set member -
i have translations class e.g.:
class translation{ string key; string type; string userid; @onetomany set<translationvalue> translations; }
which holds onetomany relationship translationvalue class e.g.:
class translationvalue{ string language; string value; @manytoone translation translation; }
i query based on translationvalue.language member , return list of translation objects contain set 1 translationvalue object -> 1 used query parameter e.g:
translationdao.findallforlanguage("en");
this return every translation object in db has translationvalue.language = "en" , furthermore remove each object translation.translations language not "en".
so far i'm returning list of translation objects have translationvalue object language="en" member in respective translations sets. need remove translationvalue objects don't have language="en" though.
edit: progress
this query returns correct amount of hits, values null. ->
@override public list<translation> findallforlanguage2(string language) { //todo:finish final query query = entitymanager.createquery( "select new " + getdomain().getsimplename() + "(t.key,t.clientname,t.userid,t.type,t.platform,tv) " + getdomain().getsimplename() + " t right join t.translations tv tv = some(from tv tv.language = :language)"); query.setparameter("language", language); return query.getresultlist(); } printing query translation: translation{key='null', clientname='null', userid='null', type=null, platform='null', translations=null} translation: translation{key='null', clientname='null', userid='null', type=null, platform='null', translations=null} translation: translation{key='null', clientname='null', userid='null', type=null, platform='null', translations=null} translation: translation{key='null', clientname='null', userid='null', type=null, platform='null', translations=null} translation: translation{key='null', clientname='null', userid='null', type=null, platform='null', translations=null} translation: translation{key='null', clientname='null', userid='null', type=null, platform='null', translations=null}
this query returns object [], second object translationvalue object want, translation object null ->
@override public list<object> findallforlanguage(string language) { //todo:finish final query query = entitymanager.createquery( "from " + getdomain().getsimplename() + " t full join t.translations tv tv = some(from tv tv.language = :language))"); query.setparameter("language", language); return query.getresultlist(); } printing query null translationvalue{language='en', value='feed'} null translationvalue{language='en', value='feed'} null translationvalue{language='en', value='broken'} null translationvalue{language='en', value='broken'} null translationvalue{language='en', value='water'} null translationvalue{language='en', value='broken'}
this query should fine
select t translation t join t.translations tv tv.language = :language , size(t.translations) = 1
Comments
Post a Comment