10:52 pm - Friday March 22, 2019

Hibernate Interview Questions and Answers- Part 7

Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

1. What is the purpose of dialect?

There are two concepts here a Dialect and a Driver,

Driver is like English.

Dialect is the different pronunciations of English.

We all know there are different versions of Oracle… Oracle 9i, Oracle8.

The driver we would use would be common for all of these.

But the dialect we use is specific to each one of them, which helps Hibernate in generating optimized queries to those specific versions of database.

Also note that this is not mandatory to be given in cfg.xml.

This is the SQL dialect (database type) for the database being used. Any valid Hibernate dialect may be used. A few the more commonly used dialects are:

  • net.sf.hibernate.dialect.HSQLDialect

  • net.sf.hibernate.dialect.Oracle9Dialect

  • net.sf.hibernate.dialect.MySQLDialect

  • net.sf.hibernate.dialect.SQLServerDialect

  • net.sf.hibernate.dialect.FirebirdDialect

2. How to create the table dynamically in hibernate?

I have managed to set up an application that inserts, retrieves, and delete objects in a database. I have also instructed hibernate to update the set of tables whenever it restarts (with hibernate.hbm2ddl.auto=update)

3. What is native SQL?

They are loosely integrated into ABAP. It allows access to all functions containing programming interface. They are not checked and converted. They are sent directly to the database system. Programs that use Native SQL are specific to the database system for which they were written. For e.g. to create or change table definition in the ABAP.

4. What are the different types of mapping?

Hibernate built-in mapping types usually share the name of the Java type they map; however, there may be more than one Hibernate mapping type for a particular Java type. The various built-in-mapping types available in Hibernate are:

  • Java primitive mapping types

  • Date and time mapping types

  • Large object mapping types

  • Various JDK mapping types

5. What is ACID properties?

The ACID properties are:

  • Atomicity

  • Consistency

  • Isolation

  • Durability

Atomicity – A transaction must be an atomic unit of work; either all of its data modifications are performed or none of them is performed.

Consistency – When completed, a transaction must leave all data in a consistent state. In a relational database, all rules must be applied to the transaction’s modifications to maintain all data integrity. All internal data structures, such as B-tree indexes or doubly-linked lists, must be correct at the end of the transaction.

Isolation – Modifications made by concurrent transactions must be isolated from the modifications made by any other concurrent transactions. A transaction either sees data in the state it was in before another concurrent transaction modified it, or it sees the data after the second transaction has completed, but it does not see an intermediate state. This is referred to as serializability because it results in the ability to reload the starting data and replay a series of transactions to end up with the data in the same state it was in after the original transactions were performed.

Durability – After a transaction has completed, its effects are permanently in place in the system. The modifications persist even in the event of a system failure.

6. What is a transaction?

A transaction is a set of rows bound by a commit or rollback of rows. The transaction control transformation is used to commit or rollback a group of rows.

7. Types of transaction:

  • Long run transaction
  • Short run transaction

8. What is isolation levels?

The following are the transaction levels or built-in variables:

  • TC_CONTINUE_TRANSACTION: The Integration Service does not perform any transaction change for this row. This is the default value of the expression.

  • TC_COMMIT_BEFORE: The Integration Service commits the transaction, begins a new transaction, and writes the current row to the target. The current row is in the new transaction.

  • TC_COMMIT_AFTER: The Integration Service writes the current row to the target, commits the transaction, and begins a new transaction. The current row is in the committed transaction.

  • TC_ROLLBACK_BEFORE: The Integration Service rolls back the current transaction, begins a new transaction, and writes the current row to the target. The current row is in the new transaction.

  • TC_ROLLBACK_AFTER: The Integration Service writes the current row to the target, rolls back the transaction, and begins a new transaction. The current row is in the rolled back transaction.

9. What is lock mode?

Here setLockMode is a method of Hibernate Criteria API. You can use a lock mode in the following way,

Criteria criteria = session.createCriteria(Student.class);

criteria.add(Restrictions.eq("name", "Ramesh"));

criteria.setLockMode("this", LockMode.UPGRADE);

List list = criteria.list();

10. Difference between session.load and session.lock

The load() method is older; get() was added to Hibernate’s API due to user request.

The difference is trivial,

The following Hibernate code snippet retrieves a User object from the database:

User user = (User) session.get(User.class, userID);

The get() method is special because the identifier uniquely identifies a single instance of a class. Hence it’s common for applications to use the identifier as a convenient handle to a persistent object. Retrieval by identifier can use the cache when retrieving an object, avoiding a database hit if the object is already cached.

Hibernate also provides a load() method:

User user = (User) session.load(User.class, userID);

If load() can’t find the object in the cache or database, an exception is thrown. The load() method never returns null. The get() method returns

null if the object can’t be found. The load() method may return a proxy instead of a real persistent instance. A proxy is a placeholder instance of a runtime-generated subclass (through cglib or Javassist) of a mapped persistent class, it can initialize itself if any method is called that is not the mapped database identifier getter-method. On the other hand, get() never returns a proxy. Choosing between get() and load() is easy: If you are certain the persistent object exists, and nonexistence would be considered exceptional, load() is a good option. If you arenot certain there is a persistent instance with the given identifier, use get() and test the return value to see if its null.

Using load() has a further implication:

The application may retrieve a valid reference (a proxy) to a persistent instance without hitting the database to retrieve its persistent state. So load() might not throw an exception when it doesn’t find the persistent object in the cache or database; the exception would be thrown later when the proxy is accessed.

 PARTS : >  1   2   3    4   5   6   7   8   9  10  11  12

Filed in: Z-A Interview Questions

No comments yet.

Leave a Reply