Home » JPA Finding an Entity

JPA Finding an Entity

by Online Tutorials Library

Finding an entity

To find an entity, EntityManger interface provides find() method that searches an element on the basis of primary key.

JPA Entity Finding Example

Here, we will search a particular record and fetch it on the console.

This example contains the following steps: –

  • Create an entity class named as StudentEntity.java under com.tutoraspire.jpa.student package that contains attributes s_id, s_name, s_age.

StudentEntity.java

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

Persistence.xml

  • Create a persistence class named as FindStudent.java under com.tutoraspire.jpa.find package to persist the entity object with data.

FindStudent.java

Output:

JPA Finding an entity

You may also like