Explain Hibernate Object States? Explain Hibernate Objects Life Cycle

Persistent objects and collections are short lived single threaded objects, which store the persistent state. These objects  synchronize their state with the database depending on your flush strategy (i.e. auto-flush where as soon as setXXX() method is called or an item is removed from a Set, List  etc or define your own synchronization points with … Read more

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

How to Improve Servlet Performance

Cache static data using jspInit() method. Release static data in jspDestroy() method. To concatenate string use, StringBuffer. Do not use println() method. Do not use PrintWriter to send binary data. Use ServletOutputStream. Always flush data in sections. Use getLastModified() method to handle browser and server cache. Use application server cache. Use session in following order: … Read more