-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Strange query generated for object with calculated field
PostPosted: Wed Aug 18, 2004 7:33 pm 
Beginner
Beginner

Joined: Thu Jul 08, 2004 8:56 am
Posts: 23
I have an Object that has a calculated field, when I try to list another object that references that object, hibernate generates an strange query, he tries to generate the code for calculating that field and this results in an wrong query. Does anybody knows what I am doing wrong? I am going to post my query code (I tried both with HQL and with Criteria API) and the mapping files.


Code:

public Lancamento[] listarLancamentos(FonteDeRecurso f) throws RepositorioLancamentosException {
Lancamento[] retorno;
List lancamentos;
try {
this.beginTransaction();
/* lancamentos = getSession().createCriteria(Lancamento.class)
.add(Expression.eq("fonteDeRecurso", f))
.list();*/
net.sf.hibernate.Query query = getSession().createQuery("select l from Lancamento as l where l.FonteDeRecurso = :fonteDeRecurso");
query.setParameter("fonteDeRecurso", f);
lancamentos = query.list();
this.commit();
retorno = (Lancamento[]) lancamentos.toArray(new Lancamento[lancamentos.size()]);
} catch (HibernateException ex) {
this.rollback();
throw new RepositorioLancamentosException("N

_________________
Rafael Ribeiro


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 19, 2004 6:53 am 
Beginner
Beginner

Joined: Thu Jul 08, 2004 8:56 am
Posts: 23
I could make it use 2 queries to fetch the lancamentos list, the first correct, that only tried to fetch lancamentos fields from its table. But on the second, it appearently tried to fetch the processo instance to fill in the property on the lancamentos instances, the problem was that it still tried to fetch from the lancamentos table, not the processos table. Any ideas what I might be doing wrong?

_________________
Rafael Ribeiro


Top
 Profile  
 
 Post subject: Found the error
PostPosted: Mon Aug 23, 2004 6:42 am 
Beginner
Beginner

Joined: Thu Jul 08, 2004 8:56 am
Posts: 23
After debugging and trying to isolate the error, I found that it was an extra this. in the formula property, so, removing it made it work fine.

_________________
Rafael Ribeiro


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.