java - hibernate createAlias with clause generates wrong query -


i have following tables: a: id b: id, text ab: aid, bid

i want joib , b b.text contains word 'cat'.

this hibernate query do:

criteria c = session.createcriteria(tablea.class, "a"); c.createalias("a.bs", "b", jointype.inner_join, restrictions.like("b.text", "%cat%")); c.setprojection(projections.property("id")); 

the generated query is:

select id  a inner join ab ab on a.id=ab.aid , (b.text ?) inner join b b on b.id=ab.bid , (b.text ?) 

for reason and (b.text ?) appears in both inner joins. far understand supposed in second on. causes following exception:

java.sql.sqlexception: no value specified parameter 2 

i guess it's happening because has 1 parameters , 2 '?'.

what missing?

edit:

adding persistent classes:

@entity @table(name="a") class {      @id     @column(name="id", length=255)     protected string id;      @onetomany     @jointable(name="ab", joincolumns = @joincolumn( name="aid"), inversejoincolumns = @joincolumn( name="bid"))     @lazycollection(lazycollectionoption.false)     protected list<b> bs;  }  @entity @table(name="b") class b {      @id     @column(name="id", length=255)     protected string id;      @column(name="text", length=255)     protected string text;  } 

i think need create alias

c.createalias("a.bs", "b", jointype.inner_join, restrictions.like("b.text", "%cat%")); 

updated

i think hibernate bug. can fix using restriction in where clause

 c.createalias("a.bs", "b", jointype.inner_join);  c.add(restrictions.like("b.text", "%cat%")); 

or don't use join table , association foreign key in b.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -