What are the general considerations or best practices for defining your Hibernate persistent classes?
The general considerations or best practices for defining your Hibernate persistent classes are:
* You must have defined no-argument constructor, getters and setters method.
* Implement the equals() and hashCode() methods based on your business key and it is important not to use the id field in your equals() and hashCode() definition if the id field is a surrogate key.
* Implement the Serializable interface.
* The persistent class should not be final.
* Use XDoclet tags for generating your *.hbm.xml files or Annotations.Reply
How would you reatach detached objects to a session when the same object has already been loaded into the session?
By using the session.merge() method call, you can reatach detached objects to a session when the same object has already been loaded into the session. Reply
What are the various services provided by the Persistence manager?
Any transparent persistent tool includes a persistence manager API, which usually provides services for:
* Baxic CRUD operation
* Query execution
* Control of transaction
* Management of the transaction-level cache.
The Persistence manager can be exposed by several different interfaces like Session, Query, Criteria, and Transaction. It provides the following services:
* Making an object persistent
* Updating the persistent state of a detached instance.
* Retrieving a persistent object.
* Updating a persistent object.
* Making a persistent object transient.
* Making a deteched object transient.Reply
What are the types of mapping class inheritance in Hibernate?
There are three different approaches to representing an inheritance hierarchy:
* Table per concrete class: Discard polymorphism and Inheritance relationships completely from the relational model.
* Table per class hierarchy: Enable polymorphism by denormalizing the relational model and using a type discriminator column to hold type information.
* Table per sublcass: Represent "is a" (Inheritance) relationships as "has a" (foreign key) relationships.Reply
Explain Fine-grained object model used in Hibernate?
A major objective of the Hibernate project is support for fine-grained object model. Fine-grained means "more classes than tables".
Hibernate emphasizes the usefulness of fine grained classes for implementing type safty and behaviour. Reply
How will you identify the database with Hibernate?
Hibernate exposes database identity to the application in two ways:
* The value of the identifier property of a persistent instance.
* The returned by Session.getIdentifier(Object o)
The Identifier property is special. Its value is the primary key value of the database row represented by the persistent instance.Reply
What is meant by Method chaining?
Method chaining is a programming technique that is supported by many hibernate interfaces. This is less readable when compared to actual java code. Look how a SessionFactory is created when we use method chaining.
SessionFactory sessions = new Configuration().addResource("myinstance/MyConfig.hbm.xml").setProperties(System.getProperties()).buildSessionFactory();Reply
What is the file extension you use for hibernate mapping file?
The file extension you use for hibernate mapping file is "filename.hbm.xml".Reply
What are different environments to configure hibernate?Reply
What are the Extension interfaces that are there in hibernate?
There are many extension interfaces provided by hibernate:
* ProxyFactory interface
* ConnectionProvider interface
* TransactionFactory interface
* Transaction interface
* TransactionManagementLookup interface
* Cahce interface
* CacheProvider interface
* ClassPersister interface
* IdentifierGenerator interface
* Dialect abstract class.