hibernate - Hiberante 3.0 inner join for two different entity with forigen key -
i new this. please me.
my controller listing looks this: @requestmapping(value="/possaleslist.htm",method=requestmethod.get) public string possaleslist(@modelattribute("possales")psales sales,@requestparam(value = "salesitemid", required = false)integer salesitemid,modelmap model) { list<possalesitem> possalesitemlist = possalesdao.listsalesitem(); model.addattribute("possaleslist", possalesitemlist);
return "possaleslist"; }
my hibernatedaoimpl looks this: @suppresswarnings("unchecked") @transactional(readonly=true) public list<possalesitem> listsalesitem() { return (list<possalesitem>)gethibernatetemplate().find("select possales.possalesid , possalesitem.itemname possales inner join possalesitem on possales.possalesid=possalesitem.possalesid"); }
my inner join looks this: select possales.possalesid , possalesitem.itemname possales inner join possalesitem on possales.possalesid=possalesitem.possalesid
the foreign key created in mysql.
what doing listing possalesid possales table , other columns possalesitem .for purpose have written join query showing error.
i want make inner join on column possalesid, these errors:
org.springframework.orm.hibernate3.hibernatequeryexception: unexpected token: on near line 1, column 111 [select possales.possalesid , possalesitem.itemname com.jewellery.entity.possales inner join possalesitem on possales.possalesid=possalesitem.possalesid]; nested exception org.hibernate.hql.ast.querysyntaxexception: unexpected token: on near line 1, column 111 [select possales.possalesid , possalesitem.itemname com.jewellery.entity.possales inner join possalesitem on possales.possalesid=possalesitem.possalesid] org.springframework.orm.hibernate3.sessionfactoryutils.converthibernateaccessexception(sessionfactoryutils.java:660) org.springframework.orm.hibernate3.hibernateaccessor.converthibernateaccessexception(hibernateaccessor.java:412) org.springframework.orm.hibernate3.hibernatetemplate.doexecute(hibernatetemplate.java:411) org.springframework.orm.hibernate3.hibernatetemplate.executewithnativesession(hibernatetemplate.java:374)
your hql syntax inner join possalesitem on possales.possalesid=possalesitem.possalesid malformed.
the correct syntax (no select necessary)
from possales s inner join s.possalesitemlist the join condition have implement in mapping (or annotations) tell class members of possalesitemlist , key column (join column) is. have hibernate documentation, one-to-many association annotations.
Comments
Post a Comment