InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
How Can I Obtain An Implementation Of The Java Persistence Api? |
|
Answer» We EXPECT many vendors to OFFER products that include implementations of the Java Persistence API that can be used with Java SE or Java EE. You can obtain the open SOURCE GlassFish project IMPLEMENTATION of the Java Persistence API. We expect many vendors to offer products that include implementations of the Java Persistence API that can be used with Java SE or Java EE. You can obtain the open source GlassFish project implementation of the Java Persistence API. |
|
| 2. |
Are Changes Needed To Existing Ejb Cmp Applications? |
|
Answer» Existing EJB CMP applications CONTINUE to work UNCHANGED, and EJB CMP technology will continue to be SUPPORTED. There is no NEED to migrate existing applications to the Java Persistence API. Further, it is possible within the same application to combine continue usage of EJB CMP entity beans with new EJB COMPONENTS that make use of the Java Persistence API. Existing EJB CMP applications continue to work unchanged, and EJB CMP technology will continue to be supported. There is no need to migrate existing applications to the Java Persistence API. Further, it is possible within the same application to combine continue usage of EJB CMP entity beans with new EJB components that make use of the Java Persistence API. |
|
| 3. |
Will The Java Persistence Api Become Part Of Java Se? |
|
Answer» There are no CURRENT plans to INCLUDE the Java Persistence API in Java SE. As the Java Persistence API evolves, however, it is LIKELY that this issue will be considered by the Java SE expert group in a FUTURE Java SE RELEASE. There are no current plans to include the Java Persistence API in Java SE. As the Java Persistence API evolves, however, it is likely that this issue will be considered by the Java SE expert group in a future Java SE release. |
|
| 4. |
How Will The Java Persistence Api Evolve Now That Jsr 220 Has Been Completed? |
|
Answer» We EXPECT to spin off the Java Persistence API into its own new JSR for FUTURE evolution. This means subsequent versions of the Java Persistence API will not be tied to future EJB JSRs. We expect to continue to DRAW EXPERTISE from a diversity of SOURCES, quite likely including many of the members of the JSR 220 Expert Group who helped define the Java Persistence API. We expect to spin off the Java Persistence API into its own new JSR for future evolution. This means subsequent versions of the Java Persistence API will not be tied to future EJB JSRs. We expect to continue to draw expertise from a diversity of sources, quite likely including many of the members of the JSR 220 Expert Group who helped define the Java Persistence API. |
|
| 5. |
What Will Happen To Other Data Persistence Apis Now That The Java Persistence Api Is Available? |
|
Answer» The Java PERSISTENCE API is now the standard API for persistence and object/relational MAPPING for the Java EE platform. Earlier APIs of course will not go away, but we expect that they will become LESS interesting once this NEW standard API is available. The Java Persistence API is now the standard API for persistence and object/relational mapping for the Java EE platform. Earlier APIs of course will not go away, but we expect that they will become less interesting once this new standard API is available. |
|
| 6. |
What If I Want To Use The Java Persistence Api Outside Of The Java Ee Platform? |
|
Answer» The SPECIFICATION, RI, and TCK insure that the JAVA Persistence API works with Java SE as well as with Java EE. Passing the TCK for the Java SE portion allows vendors to be compliant with the Java Persistence API without having a Java EE certification. The specification, RI, and TCK insure that the Java Persistence API works with Java SE as well as with Java EE. Passing the TCK for the Java SE portion allows vendors to be compliant with the Java Persistence API without having a Java EE certification. |
|
| 7. |
Why Didn't You Adopt Hibernate Or Jdo As The Persistence Api? |
|
Answer» We chose to combine the best ideas from many sources in the new persistence API and create a practical, easy to use API to meet the needs of a majority of Java EE and Java SE community members. The Java Persistence API is not based on any single existing persistence FRAMEWORK but INCORPORATES--and IMPROVES upon--ideas contributed by many popular frameworks, INCLUDING Hibernate, TOPLINK, JDO, and others. We chose to combine the best ideas from many sources in the new persistence API and create a practical, easy to use API to meet the needs of a majority of Java EE and Java SE community members. The Java Persistence API is not based on any single existing persistence framework but incorporates--and improves upon--ideas contributed by many popular frameworks, including Hibernate, TopLink, JDO, and others. |
|
| 8. |
Why Didn't You Split Off The Java Persistence Api Work Into A Separate Jsr? |
|
Answer» We believed that leveraging the work in the context of JSR-220 would minimize risk and deliver a high quality result more quickly. Further, it was important that this API integrate smoothly and consistently with the rest of the simplifications to the EJB 3.0 APIs. It therefore seemed best to extend this ongoing project, and DRAW additional experts into the JSR-220 GROUP as APPROPRIATE as the work expanded. We believed that leveraging the work in the context of JSR-220 would minimize risk and deliver a high quality result more quickly. Further, it was important that this API integrate smoothly and consistently with the rest of the simplifications to the EJB 3.0 APIs. It therefore seemed best to extend this ongoing project, and draw additional experts into the JSR-220 group as appropriate as the work expanded. |
|
| 9. |
Why Was The Java Persistence Api Developed As Part Of Jsr-220 (ejb 3.0)? |
|
Answer» The Java Persistence API originated as part of the work of the JSR 220 EXPERT Group to simplify EJB CMP entity beans. It soon became clear to the expert group, however, that a simplification of EJB CMP was not enough, and that what was needed was a POJO persistence framework in line with other O/R MAPPING technologies available in the industry. Once an Earlier Draft of the EJB 3.0 specification including the Java Persistence API was released, the JSR-220 Expert Group received many REQUESTS from the community that this work be made available beyond just the scope of EJB. The Java Persistence API originated as part of the work of the JSR 220 Expert Group to simplify EJB CMP entity beans. It soon became clear to the expert group, however, that a simplification of EJB CMP was not enough, and that what was needed was a POJO persistence framework in line with other O/R mapping technologies available in the industry. Once an Earlier Draft of the EJB 3.0 specification including the Java Persistence API was released, the JSR-220 Expert Group received many requests from the community that this work be made available beyond just the scope of EJB. |
|
| 10. |
What Are Some Of The Main Features Of The Java Persistence Api? |
|
Answer» The Java Persistence API is a POJO persistence API for object/relational mapping. It contains a FULL object/relational mapping specification SUPPORTING the use of Java language metadata annotations and/or XML descriptors to define the mapping between Java objects and a relational DATABASE. It supports a rich, SQL-like query language (which is a significant extension upon EJB QL) for both static and dynamic queries. It ALSO supports the use of pluggable persistence PROVIDERS. The Java Persistence API is a POJO persistence API for object/relational mapping. It contains a full object/relational mapping specification supporting the use of Java language metadata annotations and/or XML descriptors to define the mapping between Java objects and a relational database. It supports a rich, SQL-like query language (which is a significant extension upon EJB QL) for both static and dynamic queries. It also supports the use of pluggable persistence providers. |
|
| 11. |
What Are The Advantages Of The Java Persistence Api? |
|
Answer» The Java Persistence API draws upon the best ideas from persistence technologies such as Hibernate, TopLink, and JDO. Customers now no longer face the choice between incompatible non-standard persistence models for object/relational MAPPING. In ADDITION, the Java Persistence API is usable both within Java SE environments as well as within Java EE, allowing MANY more developers to take ADVANTAGE of a standard persistence API. The Java Persistence API draws upon the best ideas from persistence technologies such as Hibernate, TopLink, and JDO. Customers now no longer face the choice between incompatible non-standard persistence models for object/relational mapping. In addition, the Java Persistence API is usable both within Java SE environments as well as within Java EE, allowing many more developers to take advantage of a standard persistence API. |
|
| 12. |
Why Have You Introduced The New Java Persistence Api As Part Of The Java Ee 5 Platform? |
|
Answer» We INTRODUCED the Java Persistence API to the Java platform for two reasons. First, this new API SIMPLIFIES the development of Java EE and Java SE applications using data persistence. Second, we WANTED to get the entire Java community behind a SINGLE, standard persistence API. We introduced the Java Persistence API to the Java platform for two reasons. First, this new API simplifies the development of Java EE and Java SE applications using data persistence. Second, we wanted to get the entire Java community behind a single, standard persistence API. |
|
| 13. |
How To Fetch A Record Using Namedquery? |
|
Answer» public Category findByCategoryId(Long categoryId) { public Category findByCategoryId(Long categoryId) { |
|
| 14. |
Insert A Record Mechanism Using Jpa. |
|
Answer» @Override @Override |
|
| 15. |
Give An Example Of Embeddable Class For Previous Question Categoryparticipant Entity. |
|
Answer» import java.io.Serializable; if (this.categoryId != other.categoryId) { import java.io.Serializable; if (this.categoryId != other.categoryId) { |
|
| 16. |
Example Of An Entity With Embedded Class. |
|
Answer» import java.io.Serializable; import java.io.Serializable; |
|
| 17. |
What Is Jpql? |
|
Answer» JPQL (JAVA Persistence Query Language) OFFERS an object-oriented syntax for expressing query that is very similar to SQL. The language is interpreted at runtime, which means you cannot use the COMPILER to verify the correctness and integrity of a query. To adress this LIMITATION, Hibernate includes a Criteria API, which allows queries to be expressed programmatically. JPQL (Java Persistence Query Language) offers an object-oriented syntax for expressing query that is very similar to SQL. The language is interpreted at runtime, which means you cannot use the compiler to verify the correctness and integrity of a query. To adress this limitation, Hibernate includes a Criteria API, which allows queries to be expressed programmatically. |
|
| 18. |
Explain Life Cycle Of A Jpa Entity. |
|
Answer» Key states that an entity might be in:
Key states that an entity might be in: |
|
| 19. |
What Is Persistent Properties? |
|
Answer» If the entity uses PERSISTENT properties, the entity must follow the method conventions of JavaBeans components. JavaBeans-style properties USE getter and setter methods that are typically NAMED after the entity class’s instance variable names. For EVERY persistent property property of type Type of the entity, there is a getter method getProperty and setter method setProperty. If the property is a Boolean, you may use isProperty instead of getProperty. For example, if a Customer entity uses persistent properties and has a private instance variable called firstName, the class DEFINES a getFirstName and setFirstName method for retrieving and setting the state of the firstName instance variable. The method signature for single-valued persistent properties are as follows: Type getProperty() The object/relational mapping annotations for persistent properties must be applied to the getter methods. Mapping annotations cannot be applied to fields or properties annotated @Transient or marked transient. If the entity uses persistent properties, the entity must follow the method conventions of JavaBeans components. JavaBeans-style properties use getter and setter methods that are typically named after the entity class’s instance variable names. For every persistent property property of type Type of the entity, there is a getter method getProperty and setter method setProperty. If the property is a Boolean, you may use isProperty instead of getProperty. For example, if a Customer entity uses persistent properties and has a private instance variable called firstName, the class defines a getFirstName and setFirstName method for retrieving and setting the state of the firstName instance variable. The method signature for single-valued persistent properties are as follows: Type getProperty() The object/relational mapping annotations for persistent properties must be applied to the getter methods. Mapping annotations cannot be applied to fields or properties annotated @Transient or marked transient. |
|
| 20. |
What Is Persistent Fields? |
|
Answer» If the entity class uses persistent fields, the PERSISTENCE runtime ACCESSES entity-class instance VARIABLES directly. All fields not annotated javax.persistence.Transient or not marked as JAVA transient will be PERSISTED to the data store. The object/relational mapping annotations must be applied to the instance variables. If the entity class uses persistent fields, the Persistence runtime accesses entity-class instance variables directly. All fields not annotated javax.persistence.Transient or not marked as Java transient will be persisted to the data store. The object/relational mapping annotations must be applied to the instance variables. |
|
| 21. |
What Is Embeddable Classes? |
|
Answer» Entities may use persistent fields, persistent PROPERTIES, or a combination of both. If the MAPPING annotations are applied to the entity’s instance variables, the entity USES persistent fields. If the mapping annotations are applied to the entity’s getter METHODS for JavaBeans-style properties, the entity uses persistent properties. Entities may use persistent fields, persistent properties, or a combination of both. If the mapping annotations are applied to the entity’s instance variables, the entity uses persistent fields. If the mapping annotations are applied to the entity’s getter methods for JavaBeans-style properties, the entity uses persistent properties. |
|
| 22. |
Why To Use Jpa? |
|
Answer» 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 query using Java-based combinators INSTEAD of 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 deletes entities in a collection if the parent is deleted, preventing orphaning. JPA doesn’t have an equivalent to Hibernate’s ScrollableResults. 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 query using Java-based combinators instead of 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 deletes entities in a collection if the parent is deleted, preventing orphaning. JPA doesn’t have an equivalent to Hibernate’s ScrollableResults. |
|
| 23. |
What Is An Entitymanager? |
|
Answer» 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 state. These 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). 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 state. These 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). 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 state. These 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). 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 state. These 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). |
|
| 24. |
What Is The Difference Between Persistence.xml And Hibernate.cfg.xml? |
|
Answer» When using JPA need persistence.xml and while using Hibernate API need hibernate.cfg.xml. When using JPA or Hibernate not needed both XMLS, need the xml configuration file ACCORDING to JPA or Hibernate. When using JPA need persistence.xml and while using Hibernate API need hibernate.cfg.xml. When using JPA or Hibernate not needed both xmls, need the xml configuration file according to JPA or Hibernate. |
|
| 25. |
What Is Jpa And Its Key Components? |
|
Answer» 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. 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. |
|