Javatpoint Logo
Javatpoint Logo

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.javatpoint.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.javatpoint.jpa.find package to persist the entity object with data.

FindStudent.java

Output:


JPA Finding an entity




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