-->
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.  [ 5 posts ] 
Author Message
 Post subject: ICriteria.ExcludeZeroes does not work?
PostPosted: Thu Mar 16, 2006 2:12 pm 
Senior
Senior

Joined: Fri Jan 13, 2006 2:50 pm
Posts: 123
Location: Blumenau / SC / Brasil
Hi.

I'm using ExcludeZeroes() method from ICriteria and it's not working.

The mapping:

Code:
    ...
    <id name="Id" column="id" type="Int32">
         <generator class="assigned"/>
    </id>
    ...
    <property column="passwordformat" type="Int32" name="PasswordFormat" not-null="true" />
    ...


The code used to generate the QBE:

Code:
        public static IList ListByExample(object example)
        {
            ISession session = null;
            try
            {
                session = NHibernateHelper.OpenSession();
                ICriteria criteria = session.CreateCriteria(example.GetType());
                Example sample = Example.Create(example);
                sample.ExcludeZeroes();
                sample.ExcludeNulls();
                criteria.Add(sample);

                return criteria.List();
            }
            finally
            {
                NHibernateHelper.CloseSession(session);
            }           
        }


The SQL generated:

Code:
SELECT ... FROM nhuser this WHERE (this.passwordformat = 0 and ...)


The Int32 field is set = 0 on the constructor of the object. Using ExcludeZeroes() it still in the sql :(

Does ExcludeZeroes() not work? Should I use Nullable Types?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 6:14 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
The call to ExcludeNulls actually overrides the former setting of ExcludeZeroes. ExcludeZeroes excludes both nulls and zeroes, so if you remove the ExcludeNulls call, everything should work as expected.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 9:04 pm 
Senior
Senior

Joined: Fri Jan 13, 2006 2:50 pm
Posts: 123
Location: Blumenau / SC / Brasil
sergey wrote:
The call to ExcludeNulls actually overrides the former setting of ExcludeZeroes. ExcludeZeroes excludes both nulls and zeroes, so if you remove the ExcludeNulls call, everything should work as expected.


Hum, thanks sergey. I was looking the source code... that is it.

But if I want to exclude Null, Zeroes and EmptyString, is it possible?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 17, 2006 7:08 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You can create your own IPropertySelector and pass it to SetPropertySelector.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 31, 2006 6:38 am 
Beginner
Beginner

Joined: Mon Mar 20, 2006 7:59 am
Posts: 30
Hi,

I had the same problem... I think it would be best not to override the selector but to add the new selector to a list of selectors or to use the decorator pattern. Then it would make more sense to write something linke this:

Example ex = Example.Create(entity);
ex = ex.ExcludeZeroes().ExcludeNulls();

For the moment I'll write my own selector that does not only check my special conditions but also whether the property is empty ore zero or whatever.

Regards,
Dominik


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