I'm new to hibernate, and i'm trying to make a list out of 4 tables, but it's not working.
public List<DocumentoAssinanteTO> listAssinanteSemImagemByDocument(DocumentoTO documento, UsuarioDepartamentoTO ud) {
StringBuilder hql = new StringBuilder();
hql.append(" SELECT DA.id, ");
hql.append(" DOC.id,");
hql.append(" UD.id, ");
hql.append(" D.id, ");
hql.append(" U.id, ");
hql.append(" U.nome,");
hql.append(" FROM ").append(DocumentoAssinanteTO.class.getName()).append(" DA ");
hql.append(" INNER JOIN DA.documento DOC ");
hql.append(" INNER JOIN DA.usuarioDepartamento UD ");
hql.append(" INNER JOIN UD.usuario U");
hql.append(" INNER JOIN UD.departamento D");
hql.append(" WHERE DOC = :idDocumento AND UD = :idUserDep ");
hql.append(" AND U.assinatura IS NULL ");
Query query = queryTransform(hql.toString());
query.setLong("idDocumento", documento.getId());
query.setLong("idUserDep", ud.getId());
return query.list();
}
maybe it's the JOIN part, don't know if i should use INNER, LEFT or just JOIN
I want to create a hql like this sql
SELECT docass.id_documento_assinante,doc.id,
docass.id_user_depto,u.id,u.nome
FROM DCF_DOCUMENTO_ASSINANTE as docass
JOIN DCF_CONTENT as doc ON doc.id = docass.id_documento
JOIN DCF_USUARIO_DEPARTAMENTO as userDep ON userDep.id = docass.id_user_depto
JOIN DCF_USUARIOS as u ON u.id = userDep.id_usuario
WHERE u.id_anexo_assinatura is null
Ok, i got it working, made some adjusts
public List listAssinanteSemImagemByDocument(DocumentoTO documento) { StringBuilder hql = new StringBuilder(); hql.append(" SELECT DA.id, "); hql.append(" DOC.id,"); hql.append(" UD.id, "); hql.append(" U.id, "); hql.append(" U.nome "); hql.append(" FROM ").append(DocumentoAssinanteTO.class.getName()).append(" DA "); hql.append(" JOIN DA.documento DOC"); hql.append(" JOIN DA.usuarioDepartamento UD"); hql.append(" JOIN UD.usuario U"); hql.append(" WHERE DOC = :idDocumento "); hql.append(" AND U.assinatura IS NULL ");
Query query = queryTransform(hql.toString());
query.setLong("idDocumento", documento.getId());
return query.list();
}
the real problem was here the last comma. hehe
hql.append(" U.nome,");
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments