-->
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.  [ 8 posts ] 
Author Message
 Post subject: Criteria does not return Boolean field
PostPosted: Fri Oct 08, 2010 10:23 pm 
Beginner
Beginner

Joined: Sat Oct 03, 2009 1:51 pm
Posts: 26
Hello!
I have the following class:
Code:
public class House {
private Long codHouse;
private Boolean destack;
private Date dateInclusion;
// getters e setters
}

And running a query using Criteria just want to get the code and the destack value (true or false):
Code:
public List<House> listDestacks() {
      return session.createCriteria(House.class)
      .add(Restrictions.isNotNull("destack"))
      .setProjection(Projections.projectionList()
      .add(Projections.property("codHouse").as("codHouse"))
      .add(Projections.property("destack").as("destack")))
      .addOrder(Order.desc("dateInclusion")).setMaxResults(10).list();      
   }

Except that the query is not working to get the field "destack":
Code:
Hibernate:
    select
        this_.cod_house as y0_,
        this_.destack as y1_
    from
        House this_
    where
        y1_ is not null
    order by
        this_.date_inclusion desc limit ?
16:39:40,668  WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: 42703
16:39:40,668 ERROR [JDBCExceptionReporter] ERRO: column "y1_" does not exist
  Position: 79

can anyone help?
Thanks!!


Top
 Profile  
 
 Post subject: Re: Criteria does not return Boolean field
PostPosted: Sun Oct 10, 2010 9:21 am 
Regular
Regular

Joined: Sun Feb 14, 2010 3:29 pm
Posts: 58
Location: USA
Your "code and the destack" are just simple column fields, and no need to add "Projections". Remove those.

_________________
Zemian Deng
------------
Need a Java Scheduler? Try
http://bitbucket.org/timemachine/scheduler


Top
 Profile  
 
 Post subject: Re: Criteria does not return Boolean field
PostPosted: Sun Oct 10, 2010 1:04 pm 
Beginner
Beginner

Joined: Sat Oct 03, 2009 1:51 pm
Posts: 26
but this is what I want, pick only those two columns, I have many others attributes in the class that I omitted, is 10, but I want to just those two... =/


Top
 Profile  
 
 Post subject: Re: Criteria does not return Boolean field
PostPosted: Sun Oct 10, 2010 6:01 pm 
Regular
Regular

Joined: Sun Feb 14, 2010 3:29 pm
Posts: 58
Location: USA
Well, your method signature says returns List<House>, but if you are you add Projection, your returned list is not matching. Projection will give you List<Object[]>.

Perhaps you can display your hibernate-mapping file, and your full stacktrace.

_________________
Zemian Deng
------------
Need a Java Scheduler? Try
http://bitbucket.org/timemachine/scheduler


Top
 Profile  
 
 Post subject: Re: Criteria does not return Boolean field
PostPosted: Sun Oct 17, 2010 12:01 pm 
Beginner
Beginner

Joined: Sat Oct 03, 2009 1:51 pm
Posts: 26
If i use this Criteria without projections, the Criteria works, but it load all the attributes that do not need, I do not know how to return the list of homes with only the code and boolean field. =/
The problem is not mapping, is how to load list of houses with code and destack only.
Regards.


Top
 Profile  
 
 Post subject: Re: Criteria does not return Boolean field
PostPosted: Mon Oct 18, 2010 3:54 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
Try googling "resulttransformer".


Top
 Profile  
 
 Post subject: Re: Criteria does not return Boolean field
PostPosted: Mon Oct 18, 2010 10:01 am 
Beginner
Beginner

Joined: Sat Oct 03, 2009 1:51 pm
Posts: 26
Thank you CDillinger, but it did not work, does not give error but the boolean field "destack" is going null. =/
Code:
public List<House> listDestack() {
      return session.createCriteria(House.class)
         .add(Restrictions.isNotNull("destack"))
         .setProjection(Projections.projectionList()
         .add(Projections.property("codHouse"))
         .add(Projections.property("destack")))
         .addOrder(Order.desc("dateInclusion"))
         .setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP)
         .setMaxResults(10).list();
   }   


Top
 Profile  
 
 Post subject: Re: Criteria does not return Boolean field
PostPosted: Sat Oct 23, 2010 10:19 am 
Beginner
Beginner

Joined: Sat Oct 03, 2009 1:51 pm
Posts: 26
nobody??


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.