Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle Text Criteria Query in JPA

Is it possible to perform a JPA Criteria Query using Oracle Text's contains statement, and if so how?

like image 256
Ryan Avatar asked Oct 18 '11 18:10

Ryan


People also ask

How execute criteria query in JPA?

Let's see it step by step: Create an instance of Session from the SessionFactory object. Create an instance of CriteriaBuilder by calling the getCriteriaBuilder() method. Create an instance of CriteriaQuery by calling the CriteriaBuilder createQuery() method.

What is Criteria query in JPA?

The Criteria API is a predefined API used to define queries for entities. It is the alternative way of defining a JPQL query. These queries are type-safe, and portable and easy to modify by changing the syntax.

What is CriteriaBuilder in Java?

public interface CriteriaBuilder. Used to construct criteria queries, compound selections, expressions, predicates, orderings. Note that Predicate is used instead of Expression<Boolean> in this API in order to work around the fact that Java generics are not compatible with varags. Since: Java Persistence 2.0.

How does Criteria API work?

The Criteria API operates on this abstract schema to allow developers to find, modify, and delete persistent entities by invoking Java Persistence API entity operations. The Metamodel API works in concert with the Criteria API to model persistent entity classes for Criteria queries.


1 Answers

Criteria supports a function() API that allows a database function to be called by name.

qb.gt(qb.function("CONTAINS", root.get("name"), qb.parameter("name"), qb.literal(1)), 1)

EclipseLink also supports this in JPQL using the FUNC keyword.

like image 117
James Avatar answered Sep 19 '22 22:09

James