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

Thanx Andrei,

Do you have any examples with _expression_ and ReadObjectQueries .. ? Am having lots of
Expressions but not jpqls in my code . Also lots of these queries would be generated dynamically  depending on some of the query parameters that we get .

Cheers
Vaidya





On Fri, Jan 11, 2013 at 8:40 AM, Andrei Ilitchev <andrei.ilitchev@xxxxxxxxxx> wrote:
If Categories is an entity then you can use jpql:
entityManager.createQuery("SELECT c.category, c.first_name FROM Categories c WHERE FUNC('SOUNDEX', c.category) = FUNC('SOUNDEX', categoryName)");


On 1/10/2013 6:27 PM, vaidya nathan wrote:

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
<mailto: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




_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users