Interview Questions
« Previous | 0 | 1 | 2 | 3 | 4 | Next »

1.What is ORM?

ORM stands for Object-Relational Mapping ORM is a programming technique for converting data between relational databases and object oriented programming languages such as Java, C# etc.

2.What is JDBC?

JDBC stands for Java Database Connectivity and provides a set of Java API for accessing the relational databases from Java program. These Java APIs enables Java programs to execute SQL statements and interact with any SQL compliant database.

3.What are the advantages of ORM over JDBC?

An ORM system has following advantages over plain JDBC S.N. Advantages
1 Lets business code access objects rather than DB tables.
2 Hides details of SQL queries from OO logic.
3 Based on JDBC 'under the hood'
4 No need to deal with the database implementation.
5 Entities based on business concepts rather than database structure.
6 Transaction management and automatic key generation.
7 Fast development of application.
Name some of the ORM frameworks based on JAVA. There are several persistent frameworks and ORM options in Java.
Enterprise JavaBeans Entity Beans
Java Data Objects
Castor
TopLink
Spring DAO
Hibernate

4.What is Hibernate?

Hibernate is an Object-Relational MappingORM solution for JAVA and it raised as an open source persistent framework created by Gavin King in 2001. It is a powerful, high performance Object- Relational Persistence and Query service for any Java Application. Hibernate maps Java classes to database tables and from Java data types to SQL data types and relieve the developer from 95% of common data persistence related programming tasks.

5.What are the advantages of using Hibernate?

Following are the advantages of using Hibernate.
Hibernate takes care of mapping Java classes to database tables using XML files and without writing any line of code.
Provides simple APIs for storing and retrieving Java objects directly to and from the database.
If there is change in Database or in any table then the only need to change XML file properties.
Abstract away the unfamiliar SQL types and provide us to work around familiar Java Objects.
Hibernate does not require an application server to operate.
Manipulates Complex associations of objects of your database.
Minimize database access with smart fetching strategies.
Provides Simple querying of data.
Name some of the databases that hibernate supports.
Hibernate supports almost all the major RDBMS. Following is list of few of the database engines supported by Hibernate.
HSQL Database Engine
DB2/NT
MySQL
PostgreSQL
FrontBase
Oracle
Microsoft SQL Server Database
Sybase SQL Server
Informix Dynamic Server
Name some of the java based tools/frameworks that supports hibernate integration.
Hibernate supports a variety of other technologies, including the following:
XDoclet Spring
J2EE
Eclipse plug-ins
Maven

6.What are the key components/objects of hibernate?

Following are the key components/objects of Hibernate:
Configuration- Represents a configuration or properties file required by the Hibernate.
SessionFactory - Configures Hibernate for the application using the supplied configuration file and allows for a Session object to be instantiated.
Session - Used to get a physical connection with a database.
Transaction - Represents a unit of work with the database and most of the RDBMS supports transaction functionality.
Query - Uses SQL or Hibernate Query Language HQL string to retrieve data from the database and create objects.
Criteria - Used to create and execute object oriented criteria queries to retrieve objects.

7.What are the two key components of a hibernate configuration object?

The Configuration object provides two keys components:
Database Connection: This is handled through one or more configuration files supported by Hibernate. These files are hibernate.properties and hibernate.cfg.xml.
Class Mapping Setup: This component creates the connection between the Java classes and database tables.

8.What is a configuration object in hibernate?

The Configuration object is the first Hibernate object you create in any Hibernate application and usually created only once during application initialization. It represents a configuration or properties file required by the Hibernate.

9.What is a SessionFactory in hibernate?

Configuration object is used to create a SessionFactory object which inturn configures Hibernate for the application using the supplied configuration file and allows for a Session object to be instantiated. The SessionFactory is a thread safe object and used by all the threads of an application.
The SessionFactory is heavyweight object so usually it is created during application start up and kept for later use. You would need one SessionFactory object per database using a separate configuration file. So if you are using multiple databases then you would have to create multiple SessionFactory objects.

10.What is Session in hibernate?

A Session is used to get a physical connection with a database. The Session object is lightweight and designed to be instantiated each time an interaction is needed with the database. Persistent objects are saved and retrieved through a Session object.
The session objects should not be kept open for a long time because they are not usually thread safe and they should be created and destroyed them as needed.

11.What is Transaction in hibernate?

A Transaction represents a unit of work with the database and most of the RDBMS supports transaction functionality. Transactions in Hibernate are handled by an underlying transaction manager and transaction fromJDBCorJTA.
This is an optional object and Hibernate applications may choose not to use this interface, instead managing transactions in their own application code.

12.What is Query in hibernate?

Query objects use SQL or Hibernate Query Language HQL string to retrieve data from the database and create objects. A Query instance is used to bind query parameters, limit the number of results returned by the query, and finally to execute the query.

13.What is Criteria in hibernate?

Criteria object are used to create and execute object oriented criteria queries to retrieve objects.
Name some of the properties you would require to configure for a databases in a standalone
situation.
S.N. Properties and Description
1 hibernate.dialect: This property makes Hibernate generate the appropriate SQL for the chosen database.
2 hibernate.connection.driver_class: The JDBC driver class.
3 hibernate.connection.url: The JDBC URL to the database instance.
4 hibernate.connection.username: The database username.
5 hibernate.connection.password: The database password.
6 hibernate.connection.pool_size: Limits the number of connections waiting in the Hibernate database connection pool.
7 hibernate.connection.autocommit: Allows autocommit mode to be used for the JDBC connection.

14.What are the three states of a persistent entity at a given point in time?

Instances may exist in one of the following three states at a given point in time:
Transient: A new instance of a a persistent class which is not associated with a Session and has no representation in the database and no identifier value is considered transient by Hibernate.
Persistent: You can make a transient instance persistent by associating it with a Session. A persistent instance has a representation in the database, an identifier value and is associated with a Session.
Detached: Once we close the Hibernate Session, the persistent instance will become a detached instance.

15.What is the purpose of Session.beginTransaction method?

Session.beginTransaction method begins a unit of work and returns the associated Transaction object.

16.Which method is used to add a criteria to a query?

Session.createCriteria creates a new Criteria instance, for the given entity class, or a superclass of an entity class.

17.Which method is used to create a HQL query?

Session.createQuery creates a new instance of Query for the given HQL query string.

18.Which method is used to create a SQL query?

Session.createSQLQuery creates a new instance of SQLQuery for the given SQL query string.

19.Which method is used to remove a persistent instance from the datastore?

Session.delete removes a persistent instance from the datastore.

20.Which method is used to get a persistent instance from the datastore?

Session.get returns the persistent instance of the given named entity with the given identifier, or null if there is no such persistent instance.

« Previous | 0 | 1 | 2 | 3 | 4 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com