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