Javatpoint Logo
Javatpoint Logo

JPA Criteria SELECT Clause

The SELECT clause is used to fetch the data from database. The data can be retrieved in the form of single expression or multiple expressions. In Criteria API, each form is expressed differently.

Criteria SELECT Example

Generally, select() method is used for the SELECT clause to fetch all type of forms. Here, we will perform several SELECT operations on student table. Let us assume the table contains the following records: -


JPA Criteria SELECT Clause

Now, follow the below steps to perform operations: -

  • Create an entity class. Here, we created 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: -

Selecting Single Expression

Here, we will fetch single column from database with the help of a simple example.

SingleFetch.java

Output:


JPA Criteria SELECT Clause

Selecting Multiple Expression

Here, we will fetch multiple columns from database with the help of a simple example.

MultiFetch.java

Output:


JPA Criteria SELECT 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