0% found this document useful (0 votes)
2 views3 pages

SpringDataJPA-Practice

The document outlines the structure and functionality of the OwnerRepository interface, which extends JpaRepository for basic CRUD operations and custom queries. It discusses the use of named queries and the Entity class for managing data, as well as types of relationships between objects. Additionally, it mentions the use of optimistic and pessimistic locking strategies based on application requirements.

Uploaded by

ranjan patali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

SpringDataJPA-Practice

The document outlines the structure and functionality of the OwnerRepository interface, which extends JpaRepository for basic CRUD operations and custom queries. It discusses the use of named queries and the Entity class for managing data, as well as types of relationships between objects. Additionally, it mentions the use of optimistic and pessimistic locking strategies based on application requirements.

Uploaded by

ranjan patali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Interface OwnerRepository <String,Integer> extends JpaRepository<String,Integer>{

Now ownerRepository will perform basic crud operations

ownerRepository.findbyID(id)

ownerRepository.save()

ownerRepository.delete(id)

however if you want to use other fields of the Entity class for searching than

we can use

Interface OwnerRepository <String,Integer> extends JpaRepository<String,Integer>{

Optional<Owner> findbyStatus();

Or

Optional<Owner> findbyStatusandAnotherfield();

If you want to use any other complex queries you can use

@namedQuery(name = “” , query = “hql query” native=”true/false” )

@Entity (tablename = “”)

@Data

Class Owner{

@Generated

Private int Id;


}

In your Repository class you can use

Interface OwnerRepository <String,Integer> extends JpaRepository<String,Integer>{

@Query(name = “”)

Or

@Query(“ hql or sql query“ , native = true/false)

Optional<Owner> findbyStatusandAnotherfield();

Types of Relations between objects

One to one

One to many

Many to many

Employee and panCardNo  bidirectional

Father and children  one to many bidirectional

EntityManager  Managing Entity objects

PlatformTransactionManager  managing transaction

@Entity

Public class Employee{


@Id

@GeneratedValue

Private int EmpId;

For social media apps facebook twitter etc we will use optimistic locking

For banking applications financial ecommerce and airline booking etc we can use pessimistic
locking

You might also like