[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] soundex query..


Can someone point me in the right direction please? Am struck because of this issue.

Thx
Vaidya


On Wed, Jan 9, 2013 at 2:56 PM, vaidya nathan <vaidyaatdst@xxxxxxxxx> wrote:
Good Afternoon Eclipselink users,

I am trying to use soundex with eclipselink and am running into some issues.

This is the query that i want to do

SELECT category, first_name
FROM categories
WHERE SOUNDEX(category)
= SOUNDEX('subscriber');

Following is the code I have
public Category getCategoryBasedOnName(categoryName)
{
    ReadAllQuery raq = new ReadAllQuery(Categories.class);
    ExpressionBuilder builder = raq.getExpressionBuilder();
    _expression_ fnExp = ExpressionOperator.soundex().expressionFor(builder.get("category"));
    _expression_ valExp = ExpressionOperator.soundex().expressionFor(builder.getAlias(fnExp).equal(categoryName));
    ReadObjectQuery query = new ReadObjectQuery(Categories.class, valExp );
    Query jpaq = JpaHelper.createQuery(query, getEntityManager()) ;
    return jpaq ;
  }

Following is the exception that i am getting..

java.lang.ClassCastException: org.eclipse.persistence.internal.expressions.FunctionExpression cannot be cast to org.eclipse.persistence.internal.expressions.SubSelectExpression

I don't know what i am doing wrong here.. I am able to set the fnExp properly. The problem i am having is with setting the soundex on a string value. How do I do it properly?

Alternatively, how do i set the valExp properly in the above example. There are some old toplink examples that uses namedquery but i would prefer to do it with Expressions and ReadObject/ReadAll queries .. Please point me to some examples that use soundex and are eclipselink specific .

Cheers
Vaidya