issues
search
kpnishanth
/
LicenseService
0
stars
0
forks
source link
Understand JPA entity relationship, Many to One, One To Many, Many To Many
#5
Open
kpnishanth
opened
3 months ago
kpnishanth
commented
3 months ago
ManyToOne Many side is the Owner
Owner side is responsible for maintaining the foreign key relationship.
OneToMany and ManyToOne fetch lazily by default.
Many Side of the relationship usually represnted by LIst, Map or Sets.
JPQL:
@Query annotation at Repository method level. You can use Named Parameters using @Param and positions place holders as well.
@Query(value="query", nativeQuery=true)
@NamedQuery:
This is at Entity level
Add the @NamedQuery annotation in the entity class level
Add attributes Name, value =query (jpql)
IN the Repositoy method directly calll the named query using the method name equal toname attribute name of namedQuery
@NamedQueries can be used for adding multiple queries
@NamedNativeQuery
In the entity class add @namedNativeQuery annotation.
add name and value attributes
In the Reposiitory method add @Query(nativeQuery=true) -@NamedNativeQueries can be used for adding multiple @NamedNativeQueries
Pagination and Sorting:
Pagable interface and Page object
Pageable wil be passed with details of number of lines in page, page size etc..
Page will be retured as Object with the details of cuurent page,, number of total pages. details of current page., total number of records etc..
Sort method can be used of providing sort details.
Use Sort.and(sort) to add multiple conditions for sort
JPQL:
@NamedQuery:
@NamedNativeQuery
Pagination and Sorting: