querydsl-jpa dynamic query

82 views
Skip to first unread message

Simone Vratogna

unread,
Nov 28, 2016, 7:27:16 AM11/28/16
to Querydsl

Hello, 


Let's say I have a generated Entity like this:

public class QCandidate extends EntityPathBase<Candidate> {

public final com.avisto.candisearch.persistance.model.enums.QAvailabilityEnum availability;

public final DatePath<java.util.Date> birthDate = createDate("birthDate", java.util.Date.class);

public final NumberPath<Long> cvId= createNumber("cvId", Long.class);

public final StringPath city = createString("city");

}

My input values are the fields names ("availability","birthDate","cvId"...) and a string value that I should use to perform a 'like' with all the fields.

I want to build a query starting from the field names that:

  • casts to Dates and Numbers to strings and lowercases them
  • if the field is an EntityPathBase (like availability) extracts the id and then again casts to lowercased string

Something like: lower(cast(C.cvId as varchar(255))) like 'value'

for each field.

I can do this usign querydsl-sql module, but I want to achieve it using only the jpa module.

I'm not interested in the mechanism of creating the FULL 'where' clause (I know I have to use the BooleanBuilder, or at this this is what I do in the sql version).

What I want to know is how to create the individual 'where' conditions basing on the field type.

I'm trying to use a PathBuilder but it seems that to use methods like "getString or getBoolean" you already have to know the type of the field that you are trying to extract. In my case, since I start just from the field name, I can't use these methods and I don't know how to identify the type of each field starting from the field name, some I'm stuck.


Thanks.


Reply all
Reply to author
Forward
0 new messages