热门面试题与答案和在线测试
面向面试准备、在线测试、教程与实战练习的学习平台

通过聚焦学习路径、模拟测试和面试实战内容持续提升技能。

WithoutBook 将分主题面试题、在线练习测试、教程和对比指南整合到一个响应式学习空间中。

面试准备

JPA 面试题与答案

相关差异对比

JDBC vs JPAJPA vs Hibernate

问题 1. What is JPA?

JPA (Java Persistence API) is a Java EE and Java SE specification that describes a management system for saving java objects to relational database tables in a convenient form.

Java itself does not contain JPA implementations, however, there are many implementations of this specification from different companies (open and not). This is not the only way to save java objects in databases (ORM systems), but one of the most popular in the Java world.

这有帮助吗? 添加评论 查看评论
 

问题 2. What is JPA and its features?

Java Persistence API (JPA) is a collection of classes and methods to persistently store vast amounts of data in a database which is provided by the Oracle Corporation.
The Java Persistence API (JPA) is now here to simplify the developer's life. Developers can now use the JPA API to develop applications easily. Here are the features of JPA:
  • JPA supports pluggable, third-party persistence providers such as Hibernate and TopLink, etc.
  • JDK 11 annotations are fully supported.
  • Few java classes are required to develop persistence applications.
  • JPA application can run outside the container also. So, developers can use JPA capabilities in desktop applications also.
  • No need to write deployment descriptors. Annotations-based meta-data are supported in JPA applications.
  • Annotation defaults can be used in the model class, which saves a lot of development time.
  • Provides cleaner, easier, standardized object-relational mapping.
  • JPA supports inheritance, polymorphism, and polymorphic queries.
  • JPA also supports named (static) and dynamic queries.
  • JEB QL is a very powerful query language provided by JPA.
  • JPA helps you build a persistence layer that is vendor-neutral and any persistence provider can be used.
  • Many IDEs are also available to ease the development of JPA applications.
  • Some IDEs can generate the model and persistence code from the database schema.
  • JPA application can also be configured to generate database schema based on the persistence model.
  • It is also very easy to switch to the most performing persistence provider. You can easily move to any commercial persistence provider.

这有帮助吗? 添加评论 查看评论
 

问题 3. Why to use JPA?

  • JPA is the standard, and standards are good!
  • Using JPA does not tie you to Hibernate.
  • JPA gives you most of the features of plain old Hibernate, except:
  • No criteria queries in JPA 2.0. Criteria query is a neat feature of Hibernate that constructs queries using Java-based combinators instead of the alternate query language, getting the benefit of IntelliSense and Eclipse's refactoring tools.
  • JPA doesn't have Hibernate's DeleteOrphan cascade type.
  • Delete Orphan is a useful annotation that directs Hibernate to delete entities in a collection if the parent is deleted, preventing orphaning.
  • JPA doesn't have an equivalent to Hibernate's ScrollableResults.

这有帮助吗? 添加评论 查看评论
 

问题 4. What is ORM in JPA?

Mapping between database tables and java objects called ORM (Object Relational Mapping). JPA (Java Persistence API) provides and ORM facility for managing relational tables in Java applications. It is a specification and few implementations are like Hibernate, JDO, EJB, Toplink. By using JPA can be fetched data, insert, update etc.

这有帮助吗? 添加评论 查看评论
 

问题 5. What is an EntityManager?

  • Entity manager javax.persistence.EntityManager provides the operations from and to the database, e.g. find objects, persists them, remove objects from the database, etc.
  • Entities which are managed by an EntityManager will automatically propagate these changes to the database (if this happens within a commit statement). These objects are known as persistent object. 
  • If the Entity Manager is closed (via close()) then the managed entities are in a detached stateThese are known as the detached objects. If you want synchronize them again with the database, the a Entity Manager provides the merge() method. Once merged, the object(s) becomes perstent objects again.
  • The EntityManager is the API of the persistence context, and an EntityManager can be injected directly in to a DAO without requiring a JPA Template. The Spring Container is capable of acting as a JPA container and of injecting the EntityManager by honoring the @PersistenceContext (both as field-level and a method-level annotation).

这有帮助吗? 添加评论 查看评论
 

用户评价最有帮助的内容:

版权所有 © 2026,WithoutBook。