Criteria Hibernate

0 respostas
fabianofrizzo

Boa Tarde Galera..

Seguinte tenho as seguintes classes

Produto e Estoque..

Dentro de produto eu tenho uma Collection de estoque
@OneToMany(fetch=FetchType.LAZY, cascade={CascadeType.ALL})
	@JoinColumn(name="proCod_fk")
	private Collection<Estoque> estoques;

Até ai blza agora eu to com um probleminha como eu poderia montar um criteria usando projections para carregar a lista de estoques do pedido.

Eu tentei fazer dessa forma aqui

@Override
	public Produto loadById(Serializable id) throws Exception {
		super.hasObjectClass();
		super.hasSession();
		
		Criteria c = super.session.createCriteria(super.objClass,"p")
		.createCriteria("estoques","e");

		c.setProjection(Projections.projectionList()
				.add(Projections.property("p.proCod"),"proCod") 
				.add(Projections.property("p.proDesc"),"proDesc")
				.add(Projections.property("p.proAtivo"),"proAtivo")
				.add(Projections.property("p.proDescReduz"),"proDescReduz")
				.add(Projections.property("p.proUndCompra"),"proUndCompra")
				.add(Projections.property("p.proUndVenda"), "proUndVenda")
				.add(Projections.property("p.proFatorCompra"),"proFatorCompra")
				.add(Projections.property("p.proFatorVenda"), "proFatorVenda")	
		
				.add(Projections.property("e.estCod"),"estoques.estCod")
				.add(Projections.property("e.estDataCadastro"),"estoques.estDataCadastro")
				.add(Projections.property("e.estQtde"),"estoques.estQtde")
				.add(Projections.property("e.estCusto"),"estoques.estCusto")
				.add(Projections.property("e.estMargemFixa"),"estoques.estMargemFixa")
				.add(Projections.property("e.estMargemAtual"),"estoques.estMargemAtual")
				.add(Projections.property("e.estPrecoVenda"),"estoques.estPrecoVenda")	
				.add(Projections.property("e.estOfertaDe"),"estoques.estOfertaDe")
				.add(Projections.property("e.estOfertaAte"),"estoques.estOfertaAte")
				.add(Projections.property("e.estPrecoOferta"),"estoques.estPrecoOferta")				
				);
		c.add(Restrictions.eq("p.proCod", id));

		
		c.setResultTransformer(new AliasToBeanResultTransformer(Produto.class));

		return (Produto) c.uniqueResult();
	}

Mas não deu :(

da o seguinte erro

Caused by: javax.servlet.ServletException: Exception while invoking action Produ
toAction: null / java.lang.reflect.InvocationTargetException / Could not find se
tter for estoques.estCod on class entity.Produto / org.hibernate.PropertyNotFoun
dException

o certo seria ele carregar uma lista de estoques dentro do Produto..

Alguém sabe alguma forma de fazer isso
obrigado pela atenção de todos...

Criado 8 de outubro de 2008
Respostas 0
Participantes 1