简体   繁体   中英

JPA entity expression evaluator

Is there any possibility to evaluate if the JPA entity fulfils JPQL/RSQL expression using any libs or Hibernate without an active Entity Manager?

For example:

SampleEntity entity = ...;
boolean evaluationResult = new Criteria("id=gt=1").test(entity);

You may just use this library: https://github.com/turkraft/spring-filter

It will let you run search queries such as:

/search?filter= average (ratings) > 4.5 and brand.name in ('audi', 'land rover') and (year > 2018 or km < 50000) and color : 'white' and accidents is empty

You can also run search queries even if you don't have an API, the library basically compiles a search input to JPA predicates.

Blaze-Expression is a library that implements a syntax similar to JPQL and supports expression evaluation/interpretation, as well as serialization to a Blaze-Persistence query builder.

See here for an example: https://github.com/Blazebit/blaze-expression/blob/master/declarative/persistence/src/test/java/com/blazebit/expression/declarative/persistence/ModelTest.java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM