Hibernate - Subqueries.in [RESOLVIDO]

Coe galera… estou com um problemão no hibernate…
nao sei pq nao funciona a subqueries… segue o código

JobDTO.vava

package dto;
public class JobDTO implements IDefaultDTO {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//**atributos
    
    /*************************************************
     * 
     ************************************************/
    public JobDTO() {
		super();
	}

	/*************************************************
	 * gets e sets
	 ************************************************/
}

ProcessoDTO.java

package dto;

public class ProcessoDTO implements IDefaultDTO {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//*atrubutos
	/*************************************************
	 * 
	 ************************************************/
	public ProcessoDTO() {
	}
	
	/*************************************************
	 * gets e sets
	 ************************************************/
}

Job.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
                            "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                            "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping package="dto">

    <class name="JobDTO" table="tb_jobs">
        <id name="id" column="id" type="java.lang.Integer">
            <generator class="identity"/>
        </id>
        
        <!-- atributos-->
    </class>
    
</hibernate-mapping>

Processo.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="gerspool.dto">
  <class name="ProcessoDTO" table="tb_processos">
  
  		<id name="id" column="id" type="java.lang.Integer">
            <generator class="identity"/>
   		</id>
   		
   		<!-- atributos-->
   		<many-to-one name="servidorDTO" column="idserver" class="ServidorDTO" not-null="true" lazy="false"/>
   		
  </class>
</hibernate-mapping>

saida gerada pelo Hiebernate

Hibernate: select this_.id as id6_0_, this_.idserver as idserver6_0_, this_.arqentrada as arqentrada6_0_, this_.arqdados as arqdados6_0_, this_.arqintermediario as arqinter5_6_0_, this_.tamarq as tamarq6_0_, this_.numpags as numpags6_0_, this_.status as status6_0_, this_.etapa as etapa6_0_, this_.datacriacao as datacri10_6_0_, this_.datachegada as datache11_6_0_, this_.excluido as excluido6_0_, this_.processarautomaticamente as process13_6_0_, this_.tempreprocessamento as temprep14_6_0_ from tb_jobs this_ where this_.excluido=? and this_.idserver=? and ? in (select distinct this0__.id as y0_ from tb_processos this0__ where (this0__.status=? or this0__.status=?) and this0__.tipo between ? and ?)

erro

Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
	at org.hibernate.type.IntegerType.set(IntegerType.java:41)
	at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
	at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:116)
	at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1707)
	at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1678)
	at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1563)
	at org.hibernate.loader.Loader.doQuery(Loader.java:673)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
	at org.hibernate.loader.Loader.doList(Loader.java:2220)
	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
	at org.hibernate.loader.Loader.list(Loader.java:2099)
	at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
	at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
	at gerspool.dao.Teste.job(Teste.java:62)
	at gerspool.dao.Teste.main(Teste.java:27)

Teste.java

package gerspool.dao;

import dao.HibernateDAO;
import dto.JobDTO;
import dto.ProcessoDTO;
import dto.ServidorDTO;
import dto.ProcessoDTO.TEnumStatusThreads;
import dto.ProcessoDTO.TEnumTipoProcesso;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hibernate.criterion.Subqueries;

public class Teste extends HibernateDAO {

	/*************************************************
	 * @param args
	 ************************************************/
	public static void main(String[] args) {

		Teste l_teste = new Teste();
		//l_teste.subQuery();
		System.out.print(l_teste.job());
		System.exit(1);
	}

	public Teste(){
		
	}
	
	public DetachedCriteria subQuery(){
		//Criteria consulta = conexao.createCriteria(ProcessoDTO.class);
		DetachedCriteria subQuery = DetachedCriteria.forClass(ProcessoDTO.class);
		
		subQuery.setProjection(Projections.distinct(Projections.property("id")));
		subQuery.add(Restrictions.or(Restrictions.eq("status", TEnumStatusThreads.FINALIZADO.getStatus()), Restrictions.eq("status", TEnumStatusThreads.ERRO.getStatus())));
		subQuery.add(Restrictions.between("tipo", TEnumTipoProcesso.IMPRESSAO.getTipo(), TEnumTipoProcesso.EXECUTAVEL.getTipo()));
		//List l_lista = consulta.list();
		///closeConnection();
		return subQuery;
	}
	
	
	public List job(){
		
		Criteria consulta = null;
		List l_list = null;
		
		
		consulta = conexao.createCriteria(JobDTO.class);
		//consulta.setProjection(Projections.distinct(Projections.projectionList().add(Projections.property("id"))));
		consulta.add(Restrictions.eq("excluido", 1));
		consulta.add(Restrictions.eq("servidorDTO",new ServidorDTO(1)));
		consulta.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
		//consulta.setProjection(Projections.distinct(Projections.property("id")));
		consulta.add(Subqueries.in("id", subQuery()));
		
		l_list = consulta.list();
		this.closeConnection();
		return l_list;
	}

}

preciso de ajuda!

vlw!!

O problema estava na forma q era feita a subconsulta…

o certo seria…

subQuery = DetachedCriteria.forClass(ProcessoDTO.class,"ProcessoDTO");
subQuery.setProjection(Projections.distinct(Projections.property("ProcessoDTO.jobDTO")));
subQuery.add(Restrictions.eqProperty("JobDTO.id", "ProcessoDTO.jobDTO"));
consulta.add(Restrictions.eq("JobDTO.excluido", 0));
consulta.add(Restrictions.eq("JobDTO.servidorDTO",p_servidorDTO));
consulta.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
consulta.add(Subqueries.exists(subQuery));

existe um relacionamento da subconsulta com a consulta mae
conhecida como SUBCONSULTA CORRELACIONADA

subQuery.add(Restrictions.eqProperty("JobDTO.id", "ProcessoDTO.jobDTO"));

porém ou o Hibernate ainda está ficando maduro… ou eu sou mt burro ainda (a segunda opção é bem + provavel)
:smiley:

mas nao consigo fazer sql com várias subconsultas… exemplo

select *
from XX as XZ
where exists (
    select XA.id from xx as XA where not exists ( select XB.id from xx as XB where  XB.id = XA.id)
)

tentei declara DetachedCriteria e não funcionou!

me ajuda ai!!