Spring B JPA
Spring B JPA
Spring B JPA
They said, follow some interfaces & classes that you will achieve the JPA That
follows ORM. but wing JPA we can't write Complete application. we have to use
one vendar, Actually implementation of JPA is Hibernate.
[Hibernate is a JPA implementation ]
other implementation are available, but mostly large application even spring boot
internally same Hibernate
example. Eclipselink, Apache Open JPA, iBatis, TopLink.. etc
Q.59 what is Entity class of explain commonly used annotations for this?
A class mapped with Database Table is called as Entity class.
(one class -> one Table) we can also called as PoJo Class (Plain old Java object)
It must be mapped with Database table using JPA Annotations.
Like @Entity. @Table, @Id, Columb
@Unique @ Generated value etc
Q.60 what is the naming convention for finder methods in the Spring data
repository Interface?
Even we can defined our custom method By wing finder mechanism & findBy
Mechanism followed by variable name in Java class.
syntax < ReturnType> findBy <Variable name, DataType Parameter);
exg1: Post pro findByIdAndName( int id, String name)
exa2: List<User> findByName (string LName );
( no need to write any query)
Q.61 How can we create a custom repository in spring data JPA? Or How can
we create specific repository for Entity class?
Product Repository, studetRepository, EmpRepository
we use one of the below iuterfaces.
[we can create custom repository by extending any one of the below interfaces ]
repository -> create child interface
crudRepository -> by extending crudRepository
PagingAndSortingRepository
JPARepository
Repository use for custom repository
Example : public interface stRepository extends Repository<>(){ }
Mr. Raghu sir ( Spring JPA )
Q.63 @Query?
If u want to define our own query which is actually not present in the Repository.
I want to fetch 3 columns based on 2 condition then we can define @Query
annotation use. when you are writing this query make sure, you should hot write
SQL query, u should write JPQL/ HQL query.
How it is different.
(SQL query constructed using table name and column,
But JPQL/HQL constructed class name in the place of table name. Variable name
in the place of column name.)
It is case sensitive.
Here JPQL is specification and HQL is the implementation. JPAL (child) HOL
(parent) (new implement)
Based on the employee name fetch the data from the database.