Discussion:
error building Expressions: Can't resolve path component
Zvonimir Spajic
2005-05-02 13:06:38 UTC
Permalink
Hello,

1) why it's not allowed to build an expression like this
--> see qual_2 (error message: "Can't resolve path component:
[Category.id]")

...
Expression qual_1 = Expression.fromString(SomeObject.NAME_PROPERTY + "
likeIgnoreCase '%" + name + "%'");
Expression qual_2 = ExpressionFactory.matchExp("hasCategory.id",
categoryId);
qual_1 = qual_1.andExp(qual_2);
SelectQuery query = new SelectQuery(SomeObject.class, qual_1);
...

-id is the PK-Column of category table

2) what is the best solution in this cases.

Thanks for help
Zvonimir Spajic
Zvonimir Spajic
2005-05-02 13:21:20 UTC
Permalink
I tried something out, and is
this the best solution?

Without defining the id in the path (hasCategory.id), only write
hasCategory:

...
Expression qual_2 = ExpressionFactory.matchExp("hasCategory", categoryId);
...

Greets
Zvonimir
Post by Zvonimir Spajic
Hello,
1) why it's not allowed to build an expression like this
[Category.id]")
...
Expression qual_1 = Expression.fromString(SomeObject.NAME_PROPERTY + "
likeIgnoreCase '%" + name + "%'");
Expression qual_2 = ExpressionFactory.matchExp("hasCategory.id",
categoryId);
qual_1 = qual_1.andExp(qual_2);
SelectQuery query = new SelectQuery(SomeObject.class, qual_1);
...
-id is the PK-Column of category table
2) what is the best solution in this cases.
Thanks for help
Zvonimir Spajic
Andrus Adamchik
2005-05-02 13:29:38 UTC
Permalink
Hi Zvonimir,

The cleanest way is probably to use a Category object as a match parameter:

Category catgeory = // ... obtain this object instead of usig id
Expression e = ExpressionFactory.matchExp("hasCategory", category);

However if you want to match on an id, you should use "DB" flavor of
expressions. E.g.:

Expression e = ExpressionFactory.matchDbExp("hasCategory.id", categoryId);

BTW, if you use Expression.fromString, Cayenne is using "db:" prefix to
distinguish between object and database path (e.g: "db:hasCategory.id").

Hope this helps.

Andrus
Post by Zvonimir Spajic
I tried something out, and is
this the best solution?
Without defining the id in the path (hasCategory.id), only write
...
Expression qual_2 = ExpressionFactory.matchExp("hasCategory",
categoryId); ...
Greets
Zvonimir
On Mon, 02 May 2005 15:06:38 +0200, Zvonimir Spajic
Post by Zvonimir Spajic
Hello,
1) why it's not allowed to build an expression like this
[Category.id]")
...
Expression qual_1 = Expression.fromString(SomeObject.NAME_PROPERTY + "
likeIgnoreCase '%" + name + "%'");
Expression qual_2 = ExpressionFactory.matchExp("hasCategory.id",
categoryId);
qual_1 = qual_1.andExp(qual_2);
SelectQuery query = new SelectQuery(SomeObject.class, qual_1);
...
-id is the PK-Column of category table
2) what is the best solution in this cases.
Thanks for help
Zvonimir Spajic
Cris Daniluk
2005-05-02 13:35:07 UTC
Permalink
Zvonimir,

If you only have the category id and not the actual Category object, I
personally like to retrieve the object separately using DataObjectUtils
(pragmatically, you need to use the pk from time to time, but the less time
you spend internally communicating with pks, the better). This lets you use
the method Andrus recommended. It might be an extra step, but it pays
dividends in terms of clean code. On top of that, it may not even trigger a
db lookup!

An example:

Category category = (Category) DataObjectUtils.objectForPk(context,
Category.class, categoryId);

Hope that helps,

Cris
Post by Andrus Adamchik
Hi Zvonimir,
The cleanest way is probably to use a Category object as a
Category catgeory = // ... obtain this object instead of usig id
Expression e = ExpressionFactory.matchExp("hasCategory", category);
However if you want to match on an id, you should use "DB" flavor of
Expression e =
ExpressionFactory.matchDbExp("hasCategory.id", categoryId);
BTW, if you use Expression.fromString, Cayenne is using "db:"
prefix to
"db:hasCategory.id").
Hope this helps.
Andrus
Post by Zvonimir Spajic
I tried something out, and is
this the best solution?
Without defining the id in the path (hasCategory.id), only write
...
Expression qual_2 = ExpressionFactory.matchExp("hasCategory",
categoryId); ...
Greets
Zvonimir
On Mon, 02 May 2005 15:06:38 +0200, Zvonimir Spajic
Post by Zvonimir Spajic
Hello,
1) why it's not allowed to build an expression like this
[Category.id]")
...
Expression qual_1 =
Expression.fromString(SomeObject.NAME_PROPERTY + "
Post by Zvonimir Spajic
Post by Zvonimir Spajic
likeIgnoreCase '%" + name + "%'");
Expression qual_2 = ExpressionFactory.matchExp("hasCategory.id",
categoryId);
qual_1 = qual_1.andExp(qual_2);
SelectQuery query = new SelectQuery(SomeObject.class, qual_1);
...
-id is the PK-Column of category table
2) what is the best solution in this cases.
Thanks for help
Zvonimir Spajic
Zvonimir Spajic
2005-05-02 15:00:08 UTC
Permalink
thank you Cris,
thank you Andrus,

it helps.

Zvonimir




On Mon, 2 May 2005 09:35:07 -0400, Cris Daniluk
Post by Andrus Adamchik
Zvonimir,
If you only have the category id and not the actual Category object, I
personally like to retrieve the object separately using DataObjectUtils
(pragmatically, you need to use the pk from time to time, but the less time
you spend internally communicating with pks, the better). This lets you use
the method Andrus recommended. It might be an extra step, but it pays
dividends in terms of clean code. On top of that, it may not even trigger a
db lookup!
Category category = (Category) DataObjectUtils.objectForPk(context,
Category.class, categoryId);
Hope that helps,
Cris
Post by Andrus Adamchik
Hi Zvonimir,
The cleanest way is probably to use a Category object as a
Category catgeory = // ... obtain this object instead of usig id
Expression e = ExpressionFactory.matchExp("hasCategory", category);
However if you want to match on an id, you should use "DB" flavor of
Expression e =
ExpressionFactory.matchDbExp("hasCategory.id", categoryId);
BTW, if you use Expression.fromString, Cayenne is using "db:"
prefix to
"db:hasCategory.id").
Hope this helps.
Andrus
Post by Zvonimir Spajic
I tried something out, and is
this the best solution?
Without defining the id in the path (hasCategory.id), only write
...
Expression qual_2 = ExpressionFactory.matchExp("hasCategory",
categoryId); ...
Greets
Zvonimir
On Mon, 02 May 2005 15:06:38 +0200, Zvonimir Spajic
Post by Zvonimir Spajic
Hello,
1) why it's not allowed to build an expression like this
[Category.id]")
...
Expression qual_1 =
Expression.fromString(SomeObject.NAME_PROPERTY + "
Post by Zvonimir Spajic
Post by Zvonimir Spajic
likeIgnoreCase '%" + name + "%'");
Expression qual_2 = ExpressionFactory.matchExp("hasCategory.id",
categoryId);
qual_1 = qual_1.andExp(qual_2);
SelectQuery query = new SelectQuery(SomeObject.class, qual_1);
...
-id is the PK-Column of category table
2) what is the best solution in this cases.
Thanks for help
Zvonimir Spajic
--
ascensys
Software & Consulting GmbH

Individualsoftware · IT-Sicherheit · Internetlösungen · Netzwerksysteme ·
Systemintegration
individual software · security concepts · internet solutions · network
systems


Hohenzollernstrasse 114
53721 Siegburg
Germany


phone: +49 (0)2241 1277180
fax: +49 (0)2241 1469621
mobile: +49 (0)173 2050868
e-mail: mailto:***@ascensys.de
internet: http://www.ascensys.de

Confidentiality Notice: This e-mail is privileged and confidential and for
the use of the addressee only. Should you have received this e-mail in
error please notify us by replying directly to the sender or by sending a
message to the sender and delete the e-mail. Unauthorised use, disclosure
or copying of the contents of this e-mail, or any similar action, is
prohibited. Thank you.
Continue reading on narkive:
Loading...