-->
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: Criteria API + retrieving by id
PostPosted: Mon May 17, 2010 12:24 pm 
Newbie

Joined: Fri May 14, 2010 5:51 pm
Posts: 8
Hi,

I'm having a strange behavior:

I'm using the Criteria API to retrieve rows from DB filtering by ID.
Code:
        Destinatario dest = new Destinatario();
        dest.setId(new Long(2));

        Example ex = Example.create(dest);

        Session session1 = HibernateUtil.getSession();
        Transaction tx1 = session1.beginTransaction();
        Criteria criteria = session1.createCriteria(Destinatario.class);
        criteria.add(ex);
       

        List lista = criteria.list();

        for (Object object : lista) {
            Destinatario destAux = (Destinatario) object;
            System.out.println(destAux.getNome());
        }

        tx1.commit();


I'm getting this output:
Code:
Hibernate:
    select
        this_.id as id1_0_,
        this_.nome as nome1_0_,
        this_.ultima_requisicao as ultima3_1_0_
    from
        destinatario this_
    where
        (
            1=1
        )
Blue Sky
Luso


It's giving me all the rows from the table.

It should give me one single row where ID=2.

What am I doing wrong?

Any help will be much appreciated!

Irshad


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.