is it possible to convert SimplePath to StringPath?

1,184 views
Skip to first unread message

Carmnu

unread,
Aug 28, 2014, 6:41:02 AM8/28/14
to quer...@googlegroups.com
Hi I'm using RDFBean with QueryDSL.

All my mapped classes extend a class that has a field "id", whose type is "com.mysema.rdfbean.model.ID".
When I generate QClasses, the generator instantiate the field "id" as "com.mysema.query.types.path.SimplePath".

Now the problem is that I want to query about all entities whose id starts with "xxx".

So I've created a query like that:

List<Concept> titles = session.from(qv_concept).where(new StringPath(qv_concept.id.toString()).startsWith("xxx")).list(qv_concept);

My intention was to create a StringPath from a SimplePath, so that I could use all useful String methods, like startsWith in the example.

..but when i run my code it throw me an exception:

Exception in thread "main" java.lang.IllegalArgumentException: Undeclared path 'concept.id'. Add this path as a source to the query to be able to reference it.

How can I solve the problem?
Thanks in advance

Carmnu

unread,
Aug 29, 2014, 6:13:59 AM8/29/14
to quer...@googlegroups.com
I solved the problem by rewriting the query in this way:

String namespace = "blablabla";
Expression<String> matchString = ConstantImpl.create(namespace);
List<Concept> titles = session.from(qv_concept).where(PredicateOperation.create(Ops.STARTS_WITH, qv_concept.id, matchString)).list(qv_concept);

Thanks

timowest

unread,
Aug 29, 2014, 2:30:55 PM8/29/14
to quer...@googlegroups.com
Hi Carmnu.

Sorry for the delay. You can wrap the starts with operation construction with a delegate method.

Delegate methods are described here 

Timo

Carmnu

unread,
Sep 3, 2014, 3:37:14 AM9/3/14
to quer...@googlegroups.com
Thanks Timo.
It's good to know.
Reply all
Reply to author
Forward
0 new messages