我是新來的休眠,我試圖從4個表中列出一個列表, ,但它不起作用。HQL休眠很多表
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();
}
也許是連接的一部分,不知道我是否應該使用INNER,LEFT或剛剛加入
我想創建一個HQL這樣的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
joins explored:http://stackoverflow.com/questions/5706437/whats-the-difference-between-inner-join-left-join-right-join-and-full-join – dinesh707 2014-09-30 11:45:12
因爲它不是本機查詢你有沒有嘗試過它在一個本地形式的SQL服務器首先看它是否運行?導致加入+ hql我以前遇到過麻煩 – AntJavaDev 2014-09-30 11:46:47
你的'DOC'可能是一個對象,你將它與長時間比較。發佈您收到的錯誤。 – 2014-09-30 11:54:01