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