JPA Select Clause

The following two tabs change content below.
Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

Latest posts by Prasad Kharkar (see all)

Continuing with the discussion about JPA Query Language, in this article we will learn about JPA SELECT clause in simple queries. JPA Select clause can be used to retrieve managed entities.

JPA Select Clause:

Structure of a JPA Select Clause is as below according to ObjectDB

  • SELECT is mandatory.
  • FROM is mandatory.
  • Other clauses are optional and can be omitted.

A simple query with JPA Select Clause will be as follows

This is quite similar to SQL, the difference is

  • This query does not return a set of records from columns, instead it returns an entity.
  • This entity is aliased to e , it is called as identification variable.
  • This identification variable is tied to Employee type and it means result will be an entity of  Employee  type.

Another simple example of JPA Select clause will be

  •  The identification variable e navigates to firstName field of Employee entity.
  •  As it accesses the field of Employee entity,  e.name  is called as state field path.

Remember that JPA Select clause can only return single result and not a collection. The following query is illegal.

 

I hope this article helped understand JPA Select clause.

 

References for further study :

Share Button

Prasad Kharkar

Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

One thought on “JPA Select Clause

  • July 31, 2017 at 12:55 pm
    Permalink

    Hi, This article is really helpful, very simple to understand.
    Please elaborate the below statement with some example.
    Remember that JPA Select clause can only return single result and not a collection. The following query is illegal.
    Thanks,
    Suresh

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *