Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Not able to build a criteria with "like expression"
Not able to build a criteria with "like expression" [message #1008463] Tue, 12 February 2013 15:29 Go to next message
Marcus Schulz is currently offline Marcus Schulz
Messages: 5
Registered: February 2013
Location: Germany
Junior Member

Hi,

I am trying to build a criteria query with a like expression, but I am not able to find a way, it compiles. I tried the following and some hints from the wiki, but no success so far.

CriteriaBuilder cb = getEntityManger().getCriteriaBuilder();
CriteriaQuery<ST> cr = cb.createQuery(searchType);

Root<ST> root = (Root<ST>) cr.from(searchType);
EntityType<ST> type = getEntityManger().getMetamodel().entity(searchType);


String field = "name";

if (StringUtils.isNotEmpty(enteredValue)){
Predicate and = cb.Like(root.get(field), "Jeff");
cr.where(and);
}
I am using latest eclipselink stable version I think.

Here is a list of jars:

javax.persistence_2.0.4.v201112161009.jar
eclipselink-jpa-modelgen_2.4.1.v20121003-ad44345.jar
eclipselink.jar

Any help would be great, spent hours Sad

Thank you

Marcus

Re: Not able to build a criteria with "like expression" [message #1008664 is a reply to message #1008463] Wed, 13 February 2013 14:08 Go to previous message
Marcus Schulz is currently offline Marcus Schulz
Messages: 5
Registered: February 2013
Location: Germany
Junior Member

One day later I found the solution by myself.
Just, if someone also needs it:

Write
if (StringUtils.isNotEmpty(enteredValue)){
Predicate and = cb.Like(root.<String>get(field), "Jeff");
cr.where(and);
}

and everything works fine.
Previous Topic:EclipseLink merge fails to insert
Next Topic:Multitenancy and @EmbeddedId
Goto Forum:
  


Current Time: Thu Sep 18 23:46:38 GMT 2014

Powered by FUDForum. Page generated in 0.02220 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software