What is a Session? Can you Share a Session Object Between Different Threads

Session is a light weight and a non-threadsafe object (No, you cannot share it between threads) that represents a single unit-of-work with the database. Sessions are opened by a SessionFactory and then are closed when all work is complete. Session is the primary interface for the persistence service. A session obtains a database connection lazily … Read more

What is a SessionFactory? Is it a Thread-Safe Object

SessionFactory is Hibernate’s concept of a single datastore and is threadsafe so that many threads can access it concurrently and request for sessions and immutable cache of compiled mappings for a single database. A SessionFactory is usually only built once at startup. SessionFactory should be wrapped in some kind of singleton so that it can … Read more

How will you Configure Hibernate

The configuration files hibernate.cfg.xml (or hibernate.properties) and mapping files *.hbm.xml are used by the Configuration class to create (i.e. configure and bootstraphibernate) the SessionFactory, which in turn creates the Session instances. Session instances are the primary interface for the persistence service.hibernate.cfg.xml (alternatively can use hibernate.properties): These two files are used to configure the hibernate sevice … Read more

What are the Pros and Cons of an Observer Design Pattern

PROS:                                                 Loose coupling between Subject and Observer: The subject knows only a list of observers, that implementthe Observer interface, it does no know the concrete implementation of the Observer. Broadcast communication: An eventnotification is broadcast to observers irrespective of the number of Observers CONS:                                                If not used carefullythe observer pattern can add unnecessary complexity. The order of Observer notifications … Read more

Can you List some Java Interfaces that use the Observer Design Pattern

The Java Message Service (JMS) models the observer pattern, with its guaranteed delivery, non-local distribution, and persistence, to name a few of its benefits. The JMS publish-subscribe messaging model allows any number of subscribers to listen to topics of interest. When a message for the published topic is produced, all the associated subscribers are notified. … Read more