-->
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 question
PostPosted: Wed Oct 17, 2007 11:35 am 
Newbie

Joined: Tue Sep 27, 2005 9:32 am
Posts: 1
Hi, I'd need a clarification about Criteria.

I have an Oracle table, say MyTable, where I must perform a search against a VARCHAR2 field, that is obviously right-padded with spaces.

Therefore I have written a Custom user type, say my.db.customvarchar2, in order to have the filed trimmed, i.e.:

Code:
        <property name="username" type="my.db.customvarchar2">
            <column name="USERNAME" length="20" />
        </property>


then I basically do the following (Username is the reverse engineered class for username table, and userName is the username to put into test):

Code:
      Criteria criteria = session.createCriteria(Username .class);
      criteria.add(Expression.eq("username", userName));
      
      List result = criteria.list();
      
      for (Iterator iter = result.iterator(); iter.hasNext();) {
         myUser = (Username) iter.next();
         System.out.println(myUser.getUserName());
      }


The problem is that acting in this way I have an empty result set, while modifying the expression in this way:

Code:
      criteria.add(Expression.eq("username", userName+"%"));


the result set is not empty, but in this case myUser is trimmed (I see it both from console and from the debugger).

Assuming that I can check if the user exist by using findByUsername() of the UsernameDAO, how can I perform the same with Criterias?

Thanks

Ciao


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.