Q1. What is Object-Relational Mapping?
Object-relational mapping (ORM, ORM, and O/R mapping) in computer software is a programming technique for converting data between incompatible type systems in relational databases and object-oriented programming languages. We wrap the tables or stored procedures in classes in the programming language, so that instead of writing SQL statements to interact with our database, we use methods and properties of objects.
Q2. In JPA EntityManager why use persist() over merge() ?
Persist: Persist takes an entity instance and adds it to the context making that instance managed.
Merge: Merge creates a new instance of your entity, copies the state from the supplied entity, and then makes the new copy managed. Find an attached object with the same id and update it.
Q3. What are the properties of an entity?
Persistability: An object is called persistent if it is stored in the database and can be accessed anytime.
Persistent Identity: In Java, each entity is unique and represents an object identity. Similarly, when the object identity is stored in a database, then it is represented as a persistence identity. This object identity is equivalent to the primary key in the database.
Transactionality: A transaction is a set of operations that either fail or succeed as a unit. Transactions are a fundamental part of persistence.
Granularity: Entities should not be primitives, primitive wrappers, or built-in objects with a single-dimensional state.
Q4. What is the role of the Entity Manager in JPA?
An entity manager is responsible for the following roles in JPA. The entity manager has the role to manage an object referenced by an entity. It implements the API and encapsulates all of them within a single interface. It is used for operations like reading, deleting, and writing an entity.
Q5. What is the Spring data repository?
Spring data repository is a very important feature of JPA. It helps in reducing a lot of boilerplate code. Moreover, it decreases the chance of errors significantly. This is also the key abstraction that is provided using the Repository interface. It takes the domain class to manage as well as the id type of the domain class as Type Arguments.
Q6. What is the difference between JPA and JDO?
JPA and Java Data Objects (JDO) are two specifications for storing java objects in databases. If JPA is concentrated only on relational databases, then JDO is a more general specification that describes the ORM for any possible bases and repositories. JDO, from an API point of view, is agnostic to the technology of the underlying datastore, whereas JPA is targeted to RDBMS datastores. JPA can be viewed as part of the JDO specification specialized in relational databases, even though the API of these two specifications does not completely match.
Q7. How can we create a custom repository in Spring Data JPA?
Repository
PagingAndSortingRepository
CrudRepository
JpaRepository
QueryByExampleRepository
Q8. What is the difference between CrudRepository and JpaRepository interfaces in Spring Data JPA?
CrudRepository provides CRUD functions. PagingAndSortingRepository provides methods to do pagination and sort records.
JpaRepository provides JPA-related methods such as flushing the persistence context and deleting records in a batch.
Q9. What requirements does JPA set for Embeddable classes?
Such classes must satisfy the same rules as the Entity classes, except that they do not have to contain a primary key and be marked with the Entity annotation. The Embeddable class must be marked with the Embeddable annotation or described in the XML configuration file JPA.
Q10. What is the purpose of cascading operations in JPA?
If we apply any task to one entity then using cascading operations, we make it applicable to its related entities also.
Q11. What are the types of cascade supported by JPA?
PERSIST: In this cascade operation, if the parent entity is persisted then all its related entities will also be persisted.
Exception Handling Interview Questions
DBMS Interview Questions Set -1
DBMS Interview Questions Set -2
JPA Interview Questions Set -1
Spring Boot Interview Questions Set 1
Spring Boot Interview Questions Set 2
Core Java Interview Questions Set -1
Docker interview question Set -1
Docker interview question Set -2
No comments:
Post a Comment