Javatpoint Logo
Javatpoint Logo

JPA Criteria WHERE Clause

The WHERE clause is used to apply conditions on database and fetch the data on the basis of that condition. In Criteria API, the where() method of AbstractQuery interface is used to set conditions.

Criteria WHERE Example

Here, we will perform several WHERE operations on student table. Let us assume the table contains the following records:-


JPA Criteria WHERE Clause

Now, follow the below steps to perform operations: -

  • Create an entity class names as StudentEntity.java under com.javatpoint.jpa package. This class contains three attributes s_id, s_name, s_age with all the required annotations.

StudentEntity.java

  • Now, map the entity class and other databases confiuguration in Persistence.xml file.

Persistence.xml

  • Once, we have created the basic entity class and mapped the configuration into persistence.xml file, we can perform the different types of select operations in the following ways: -

JPQL Greater Than and Less Than

Comparison.java

Output:


JPA Criteria WHERE Clause

JPQL Between

Between.java

Output:


JPA Criteria WHERE Clause

JPQL Like

Like.java

Output:


JPA Criteria WHERE Clause

JPQL In

In.java

Output:


JPA Criteria WHERE Clause




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA