Use WHERE clause with instances in hql -
how select record table using clause , comparing instances (patient)
public history findhistory(patient patient) { history model=null; session sesion=util.hibernateutil.getsessionfactory().getcurrentsession(); string sql="from history h h.patients=" + patient; try{ sesion.begintransaction(); model=(history) sesion.createquery(sql).uniqueresult(); sesion.begintransaction().commit(); } catch(exception e){ sesion.begintransaction().rollback(); } homecoming model; } that throws queryexception #1562 e.querystring="from entidad.historia h h.pacientes=entidad.paciente@3ad3a221" e.detailmessage="unexpected char: '@'"
the problem code concatenating patient append patient.tostring(), in case default implementation (i.e. classname@hashcode) , no utilize hibernate find out info retrieve in db.
you need bind parameter, first:
string sql = "from history h h.patients = :patient"; then
model = (history) sesion.createquery(sql) .setparameter("patient", patient) .uniqueresult(); edit:
sqlgrammarexception: not execute query can occurs various reason. seek run generated query in sqldeveloper (or other tool) , see db says. in case, lastly part and .=? cause error. cross join harming too. suspect mapping incomplete , hibernate can't find how bring together history , patient. seek add together in history entity:
@manytoone @joincolumn(name = "patient") private patient patient; hql
No comments:
Post a Comment