-->
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.  [ 1 post ] 
Author Message
 Post subject: Mysql - hql with DATE_ADD function
PostPosted: Sun Aug 07, 2011 10:21 am 
Newbie

Joined: Sun Aug 07, 2011 9:39 am
Posts: 1
Hello guys!!!

I have a mysql table called INTEGRANTE with a date field mapped :

Code:
    @Temporal(TemporalType.DATE)
    @Column(name = "INTE_DT_ULTIMA_RENOVACAO_SMV", nullable=true)
    private Date dataUltimaRenovacaoSmv;


I built the following query:

Code:

        Map<String, Object> map = new HashMap<String, Object>();

        texto
                .append(" select distinct i from {Integrante} i ")
                .append(" where 1=1 ");


        if (diasVencimentoSmv!=null) {

            Date hoje = DateUtils.truncate(new Date(), Calendar.DATE);

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(hoje);
            calendar.add(Calendar.DAY_OF_MONTH, diasVencimentoSmv);
            Date vencimento = DateUtils.truncate(calendar.getTime(), Calendar.DATE);

            String interval = "DATE_ADD(DATE(i.{dataUltimaRenovacaoSmv}), INTERVAL 1 YEAR)";

            texto.append(" and (:interval BETWEEN :hoje AND :vencimento) ");

            map.put("hoje", hoje);
            map.put("vencimento", vencimento);
            map.put("interval", interval);

        }

        texto.append(" order by u.{nome} ");

        String hql = texto.toString();

        hql = hql.replace("{Integrante}", Integrante.class.getSimpleName())
                 .replace("{dataUltimaRenovacaoSmv}", Integrante.PROPRIEDADE_DATA_ULTIMA_RENOVACAO_SMV)
                 .replace("{nome}", Usuario.PROPRIEDADE_NOME);

        this.setText(hql);
        setParameters(map);




directly run the generated sql returns data, but through the application using hibernate returns nothing.
what might be wrong?
help, please!!!


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

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.