0% found this document useful (0 votes)
16 views2 pages

HW 4

Uploaded by

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

HW 4

Uploaded by

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

Homework 4

1 – What is JPA ?

JPA(Java Persistence API) is a technology that associates objects with relational database tables and does not forget these relationships, which we can continue to
use later. * With JPA, developers can work directly on objects instead of SQL commands, and JPA contains SQL queries. * JPA creates the interface point between
the application and the database. * JPA is concerned with how the data will be mapped on the database, the security and performance of the data. * JPA is a
technology available for both Java SE and Java EE. * Hibernate, TopLink, EclipseLink and OpenJPA are the main tools that implement JPA. * With JPQL, we can
provide database communication with classes and objects, thanks to the Java Persistence API.

2 - What is the naming convention for finder methods in the Spring data repository interface ?

The finder method should use a special keyword like "find", followed by the name of the variable.The query is prepared by Spring Data JPA according to the defined
method names and parameter value.In this way, it is sufficient to define and use a method in the repository according to the desired result. For example:

List<Cat> findByNameOrAge(String name, Integer age);

Some examples of naming convention:

Method Naming Jpql Equivalent

… where x.active =
findByActiveTrue()
true

findByAgeGreaterThanEqual … where x.age >= ?1

findByAge(Is)NotNull … where x.age not null

3 - What is PagingAndSortingRepository?

PagingAndSortingRepository is the interface that extends from CrudRepository to provide additional methods to retrieve entities using pagination and sorting. It
provides two method: * Page findAll(Pageable pageable): returns a Page of entities meeting the paging restriction provided in the Pageable object. * Iterable
findAll(Sort sort) :returns all entities sorted by the given options.

4 - Differentiate between findById() and getOne()?

The getOne() method returns the reference of the object of the given id. This method always returns a proxy without going to the database (lazy fetch). Throws
EntityNotFoundException if the requested entity is not found in the database. Each time the findById method is called, it goes to the database and retrieves the object
from there. This is the EAGER loaded transaction, so if the object we are trying to fetch is not in the DB, it will return null. * The getOne method offers better
performance, while the findById method requires an additional database query. * Since the object is retrieved completely with the findById method, all its properties
can be accessed, while it cannot be accessed with the getOne method.

5 - What is @Query used for?

Query annotation is used to create queries over objects created from classes called Entities that are mapped to database tables.Spring Data JPA @Query annotation
is used on Repository interface.The @Query annotation contains the custom JPQL querty.For our methods, we can write sql-like queries in query annotation with Jpql.
For Example:

@Query("From JobExperience j Inner join j.curriculumVitae c Where c.jobSeeker.id=:id Order By j.endDate desc")
List<JobExperience> getAllJobExperienceByJobSeekerIdByDate(int id);

This method returns a list of previous job experiences sorted by descending date by a job seeker's id which is taken from parameter.

6 - What is lazy loading in hibernate?

In Hibernate, the relation between objects differs in pulling the data in the database.These are called Lazy loading and Eager loading. Lazy loading is known as the
concept of delaying the loading of an object until it is needed.With Lazy loading, we shorten the initial processing time by pulling the data you won't need right away,
later when needed.Lazy loading in hibernate improves the performance. It loads the child objects on demand.If we are not sure to use the associated object, we
should use lazy loading.

7 – What is SQL injection attack? Is Hibernate open to SQL injection attack?

8 - What is criteria API in hibernate?

9 - What Is Erlang? Why Is It Required For Rabbitmq?

Erlang is a general-purpose, concurrent, dynamic, functional programming language that also has garbage collection feature.RabbitMQ is written using Erlang
programming language and Erlang language must be installed on the system for it to work in our environment.RabbitMQ runs in Erlang virtual runtime.
10 – What is the JPQL?

JPQL (Java Persistence Query Language) is a query language used to query SQL-like JPA Entity objects.The main difference between SQL and JPQL is that SQL
works with relational database tables, whereas JPQL works with Java classes and objects. Example of JPQL

@Query("From Product where productName=:productName and category.categoryId=:categoryId")


List<Product> getByNameAndCategory(String productName, int categoryId);

This method will return a list of suitable products according to the product name and category id taken from the parameter.

11 – What are the steps to persist an entity object?

12 – What are the different types of entity mapping?

13 - What are the properties of an entity?

14 - Difference between CrudRepository and JpaRepository in Spring Data JPA?

CrudRepository and JPA repository both are the interface of the spring data. * JpaRepository extends the PagingAndSorting repository which is extended from
CrudRepository. * CrudRepository is the base interface. * While CrudRepository provides only crud methods like findOne * JpaRepository extends the
PagingAndSorting repository that provides the pagination and sorting for us. * CrudRepository doesn't provide pagination and sorting methods. * While JPA also
provides some extra methods like flush(),saveAndFlush(),but CrudRepository provides only crud functions.

You might also like