I have a J2EE application with Hibernate2.
I need execute a SQL like this:
Code:
select ac.*
from actividades ac, actividades_linea li
where ac.ACTI_CODIGO_ACTIVIDAD = li.ACLI_CODIGO_ACTIVIDAD
and li.ACLI_CODIGO_LINEA = 'CC'
OR
Code:
SELECT ac.* FROM ACTIVIDADES ac inner join ACTIVIDADES_LINEA li ON li.ACLI_CODIGO_ACTIVIDAD = ac.ACTI_CODIGO_ACTIVIDAD WHERE li.ACLI_CODIGO_LINEA = 'CC'
I have proven with createSQLQuery function:
Code:
sql = "";
sql += "SELECT {ac}.ACTI_CODIGO_ACTIVIDAD AS {ac.codigoAC} ";
sql += "FROM ACTIVIDADES {ac} ";
sql += "inner join ACTIVIDADES_LINEA {li} ON {li}.ACLI_CODIGO_ACTIVIDAD = {ac}.ACTI_CODIGO_ACTIVIDAD ";
sql += "WHERE {li}.ACLI_CODIGO_LINEA = 'CC'";
Query storeQuery = sess.createSQLQuery(sql, new String[] {"ac","li"}, new Class[] { Actividad.class, ActividadLinea.class} );
List storeList = storeQuery.list();
But jump a Exception.
There is some simple method to execute a SQL with joins?