Please be informed that NONE of the design/code from this
page is claiming to be some sort of best practices and we DO NOT expect
any of our visitor/reader of this page to assume this as some sort of
best practice for any context and should not be using this
as it is without appropriate evaluation to their, so to say,
specific programming context.
This page intends only to provide bit and piece of known ways for
doing some sort of example and may not be fit for any other purpose.
Hibernate Question :
What are the different Transaction Factories available with Hibernate?
Hibernate Answer :
There are three different types of Transaction Factoryavailable with Hibenate 3.2 as JDBCTransactionFactory,
JTATransactionFactory and CMTTransactionFactory.
Hibernate Question :
Which one is the default transaction factory in Hibernate 3.2?
Hibernate interview answer
JDBCTransactionFactory is the default local
transaction factory withHibernate 3.2.
| |
Hibernate interview question
Can Hibernate Session Factory be
bound to JNDI?
Hibernate interview answer
Yes, by configuring in
hibernate.cfg file, session
factory can be bound to initial
context (as defined by
properties hibernate.jndi.url
and hibernate.jndi.class).
Hibernate interview question
Can Hibernate be used to call
stored procedures and SQL
statements?
Hibernate interview answer
Yes, there are provision in Hibernate 3.2, for defining
callable statements and SQL in mapping HBM files.
Hibernate interview question
Can the custom SQL be defined for creation of Java entity
object by loading values from database tables and
populating Java Object?
Hibernate interview answer
Yes, Javaentity objects can be loaded with custom SQL
queries and can be defined in HBM file in form of
HQL (Hibernate Query Language).
Hibernate interview question
What are the different Fetching Strategies available
with Hibernate 3.2?
Hibername interview answer
There are four different Fetching standards available in
Hibernate3.2, as follows: join fetching, select fetching,
batch fetching, sub-select fetching.
Hibernate interview question
What are the different types of statistics available in
Hibernate 3.2?
Hibernate interview answer
Different types of statistics like QueryStatistics,
CategorizedStatistics, CollectionStatistics, EntityStatistics
etc., available in Hibernate 3.2.
Hibernate interview question
How can you get a handle on Hibernate Statistics?
Hibernate interview answer
If Hibernate is deployed in a JMX enabled Application
server, then Hibernate provided a statistics service,
that can be registered as MBean with JMX server and be
used to retrieve different types of statistics available.
Hibernate statistics can be obtained from session
factory as well.
Hibernate interview question
Can Hibernate be used to map persistent entity POJO to
XML files?
Hibernate interview answer
Yes, Hibernate can be used to mapp XML file/tags to
POJO entity classes.
Hibernate Question : If there are
multiple databases to be
used to interact with domain
classes, how can session
factory be able to manage
multiple datasources?
Hibernate Answer :
Each datasource will be
configured to each session
factory, and to use a single
database, a session is
created to use database.
Question : What is lazy initialization in Hibernate?
Answer :
When there is an association of one-to-one, or
one-to-many, or many-to-many between classes,
and on creation of one object, it has to be
decided whether to bring associated objects along
with this object or not. By setting lazy="true"
we instruct Hibernate not to bring the associated
object/objects during creation of the required object.
By setting lazy="false", it is the reverse, this means
we instruct Hibernate to bring all the associated
objects also at the time of returning the associating
object.
Hibernate interview Question : if there any impact on performance
by this attribute lazy ?
Hibernate interview Answer :
This is purely a configuration time decision one has
to take to use lazy attribute and its value (true/false)
appropriately. As SessionFactory is created once and reused,
all the configuration setting in HBM file is read once,
and cann't be changed at runtime.
Hibernate Question : What are the different states
of an instance in Hibernate?
Hibernate Answer :
There are three states that exist for any instance of a
class. These are transient, persistent and detached.
Those instances that are created but not associated with
any session or not saved in database are trasient objects.
Those instances that are created and be used in any of the
methods like save, saveOrUpdate, update of Session are
called persistent objects.
Those instances that were used in Session methods like save,
saveOrUpdate or update to be inserted or updated in database
table, and then session is flushed and closed, now these
objects are in JVM, but these are not bound to any session.
Hibernate interview question
How can certain type of logic executed on execution of
CRUD operation of session, without duplicating it across
many places in code base?
Hibernate interview answer
Hibernate Interceptors can be used to receive callback
for certain type of events or operations like save, delete,
load, update of session. Session Factory level interceptor
and session level interceptor. These Interceptors can be
used to have code for certain type of logic to be called
for every lifecycle method of session.
Hibernate interview question
How can multiple threads access session factory
simulteneously to create session instance?
Hibernate interview answer
session factory is thread-safe, so it is okay to be used
by many threads to have session from session factory,
but I think session is not thread safe and it should be
used by one thread at a time, and after use,
session has to be flushed and closed.
Hibernate interview question
How many ways Hibernate manages concurrency ?
Hibernate interview answer
Hibernate has different ways of managing concurrency.
These are automatic versioning, detached object and
extended user sessions.
Hibernate interview question
What is the difference between uni-directional and
bi-directional associations?
Hibernate interview answer
uni-directional association allows object creation from
one direction only. Bi-directional association allows
object querying from both directions of fetching object
instances.
A->B, now querying A, can provide information on B as
well, based on lazy parameter, but in case of A<->B,
querying either A or B, will have value of B or A as
well, respectively.
Hibernate interview Question
What are the different contextual session in Hibernate?
Hibernate interview answer
There are three different types
of contextual session Hibernate
provides, these are JTA session
context, local thread session
context and managed session
context. JTA session context is
applicable in case Hibernate
session is running in JTA (Java
Transaction API), request thread
level session scoped applicable
in case of local thread session,
and managed session, requires
application to open, close and
flush session, so creation of
session should be handled by
application only.
Hibernate interview Question
Can you tell us difference between Hibernate HQL over SQL?
Hibernate interview answer
HQL is fully object oriented, with support for object
inheritence, polymorphism and association, but SQL
is more of Relational with structured form of queries.
Hibernate interview Question
What are the different scopes one can introduce while using
Interceptors with Hibernate?
Hibernate interview Answer
Probably, one can use interceptors with hibernate Session
scoped or SessionFactory scoped contexts, while using
Interceptors with Hibernate.
Hibernate interview Question
How many ways client application that uses Hibernate to
react to certain events?
Hibernate interview Answer
Probably, if I am not wrong, two ways one can react/act
to certain events generated out of Hibernate Framework.
These are either Interceptors or event systems.
Hibernate interview Question
Can I be able to persist a XML DOM object tree to database
by defining mapping between XML DOM to database table,
without using POJOs?
Hibernate interview Answer
Yes, one can use Hibernate mapping to persist XML DOM tree
hierarchy to database tables.
Disclaim: These materials mentioned as above,
are my understanding of Hibernate, for details and
complete information, please refer to Hibernate
site http://www.hibernate.org/
|
|