Configuration cfg = new Configuration();
cfg.addResource("myinstance/MyConfig.hbm.xml");
cfg.setProperties( System.getProperties() );
SessionFactory sessions = cfg.buildSessionFactory();
First, we need to create an instance of Configuration and use that instance to refer to the location of the configuration file. After configuring this instance is used to create the SessionFactory by calling the method buildSessionFactory().
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. And it is not mandatory to use this format. Look how a SessionFactory is created when we use method chaining.
SessionFactory sessions = new Configuration()
.addResource("myinstance/MyConfig.hbm.xml")
.setProperties( System.getProperties() )
.buildSessionFactory();
What Does Hibernate.properties File Consist Of?
This is a property file that should be placed in application class path. So when the Configuration object is created, hibernate is first initialized. At this moment the application will automatically detect and read this hibernate.properties file.
hibernate.connection.datasource = java:/comp/env/jdbc/AuctionDB
hibernate.transaction.factory_class =
net.sf.hibernate.transaction.JTATransactionFactory
hibernate.transaction.manager_lookup_class =
net.sf.hibernate.transaction.JBossTransactionManagerLookup
hibernate.dialect = net.sf.hibernate.dialect.PostgreSQLDialect
What Should Sessionfactory Be Placed So That It Can Be Easily Accessed?
As far as it is compared to J2EE environment, if the SessionFactory is placed in JNDI then it can be easily accessed and shared between different threads and various components that are hibernate aware. You can set the SessionFactory to a JNDI by configuring a property hibernate. session_ factory_ name in the hibernate. properties file.
What Are Pojos?
POJO stands for plain old java objects. These are just basic JavaBeans that have defined setter and getter methods for all the properties that are there in that bean. Besides they can also have some business logic related to that property. Hibernate applications works efficiently with POJOs rather then simple java classes.
Adobe Systems Most Frequently Asked Latest Advanced Java Interview Questions Answers |
What Is Object/relational Mapping Metadata?
ORM tools require a metadata format for the application to specify the mapping between classes and tables, properties and columns, associations and foreign keys, Java types and SQL types. This information is called the object/relational mapping metadata. It defines the transformation between the different data type systems and relationship representations.
What Is Hql?
HQL stands for Hibernate Query Language. Hibernate allows the user to express queries in its own portable SQL extension and this is called as HQL. It also allows the user to express in native SQL.
What Is Attribute Oriented Programming?
XDoclet has brought the concept of attribute-oriented programming to Java. Until JDK 1.5, the Java language had no support for annotations; now XDoclet uses the Javadoc tag format (@attribute) to specify class-, field-, or method-level metadata attributes. These attributes are used to generate hibernate mapping file automatically when the application is built. This kind of programming that works on attributes is called as Attribute Oriented Programming.
What Are The Different Methods Of Identifying An Object?
There are three methods by which an object can be identified.
i. Object identity –Objects are identical if they reside in the same memory location in the JVM. This can be checked by using the = = operator.
ii. Object equality – Objects are equal if they have the same value, as defined by the equals( ) method. Classes that don’t explicitly override this method inherit the implementation defined by java.lang.Object, which compares object identity.
iii. Database identity – Objects stored in a relational database are identical if they represent the same row or, equivalently, share the same table and primary key value.
What Are The Different Approaches To Represent An Inheritance Hierarchy?
i. Table per concrete class.
ii. Table per class hierarchy.
iii. Table per subclass.
What Are Managed Associations And Hibernate Associations?
Associations that are related to container management persistence are called managed associations. These are bi-directional associations. Coming to hibernate associations, these are unidirectional.
Why Do You Need Orm Tool Like Hibernate?
ORM tools like hibernate provide following benefits
• Improved performance: Lazy loading, Sophisticated caching, Eager loading.
• Improved productivity: High-level object-oriented API, Less Java code to write, No SQL to write.
• Improved maintainability: A lot less code to write.
• Improved portability: ORM framework generates database-specific SQL for you.
What Are The Main Advantages Of Orm Like Hibernate?
Hibernate implements extremely high-concurrency architecture with no resource-contention issues. This architecture scales extremely well as concurrency increases in a cluster or on a single machine.
Other performance related optimizations that hibernate performs are
• Caching objects
• Executing SQL statements later, when needed
• Never updating unmodified objects
• Efficient Collection Handling
• Rolling two updates into one
• Updating only the modified columns
• Outer join fetching
• Lazy collection initialization
• Lazy object initialization.
What Are The Core Interfaces Of Hibernate Framework?
1. Session Interface: The basic interface for all hibernate applications. The instances are light weighted and can be created and destroyed without expensive process.
2. SessionFactory interface: The delivery of session objects to hibernate applications is done by this interface. For the whole application, there will be generally one SessionFactory and can be shared by all the application threads.
3. Configuration Interface: Hibernate bootstrap action is configured by this interface. The location specification is specified by specific mapping documents, is done by the instance of this interface.
4. Transaction Interface: This is an optional interface. This interface is used to abstract the code from a transaction that is implemented such as a JDBC / JTA transaction.
5. Query and Criteria interface: The queries from the user are allowed by this interface apart from controlling the flow of the query execution.
What Is A Hibernatetemplate?
HibernateTemplate is a helper class that is used to simplify the data access code. This class supports automatically converts HibernateExceptions which is a checked exception into DataAccessExceptions which is an unchecked exception. HibernateTemplate is typically used to implement data access or business logic services. The central method is execute(), that supports the Hibernate code that implements HibernateCallback interface.
What Are The Benefits Of Hibernatetemplate?
The benefits of HibernateTemplate are
• HibernateTemplate, which is a Spring Template class, can simplify the interactions with Hibernate Sessions.
• Various common functions are simplified into single method invocations.
• The sessions of hibernate are closed automatically.
• The exceptions will be caught automatically, and converts them into runtime exceptions.
What Is Hibernate Proxy?
Mapping of classes can be made into a proxy instead of a table. A proxy is returned when actually a load is called on a session. The proxy contains actual method to load the data. The proxy is created by default by Hibernate, for mapping a class to a file. The code to invoke Jdbc is contained in this class.
Explain The Types Of Hibernate Instance States.
The persistent class’s instance can be in any one of the three different states. These states are defined with a persistence context. The Hibernate has the following instance states
• Transient: This instance is never been associated with any one of the persistence process. This does not have persistent identity like primary key value.
• Persistent: A persistent context is made to associate with the current instance. It has persistent identity like primary key value and a corresponding row of a table in the data base. Hibernate guarantees the persistent identity is equivalent to the java Identity [object], for a particular persistence context.
• Detatched: This instance association with a persistence context is only once and the context was closed or serialized to another process. The persistent identity is retained and it can be a corresponding row in a database.
What Are Collection Types In Hibernate?
• ArrayType,
Constructor: ArrayType(String role, String propertyRef, Class elementClass, boolean isEmbeddedInXML)
• BagType,
Constructor: BagType(String role, String propertyRef, boolean isEmbeddedInXML)
• CustomCollectionType, A custom type for mapping user-written classes that implement PersistentCollection Constructor: CustomCollectionType(Class userTypeClass, String role, String foreignKeyPropertyName, boolean isEmbeddedInXML)
• IdentifierBagType,
Constructor: IdentifierBagType(String role, String propertyRef, boolean isEmbeddedInXML)
• ListType,
Constructor: ListType(String role, String propertyRef, boolean isEmbeddedInXML)
• MapType,
Constructor: MapType(String role, String propertyRef, boolean isEmbeddedInXML)
• SetType
Constructor: SetType(String role, String propertyRef, boolean isEmbeddedInXML)
What Is Lazy Initialization In Hibernate?
The delaying the object creation or calculating a value or some process until the first time it is needed. The retrieval of particular information only at the time when the object is accessed, is lazy initialization in hibernate. A scenario for lazy initialization is
When the field creation is expensive, a field may or may not be invoked.
In this scenario the creation of a field can be deferred until the actual moment is arise to use it. The performance is increased using this technique, by avoiding unnecessary creation of objects which is expensive and consumes the memory space.
What Is Lazy Fetching In Hibernate?
• Lazy setting decides whether to load child objects while loading the Parent Object.
• This can be done by a setting in hibernate mapping file of the parent class.Lazy = true.
• By default the lazy loading of the child objects is true.
What Is The Difference Between Sorted And Ordered Collection In Hibernate?
Sorted Collection
The sorted collection is a collection that is sorted using the Java collections framework. The sorting is done in the memory of JVM that is running hibernate, soon after reading the data from the database using Java Comparator.
The less the collection the more the efficient of sorting.
Ordered Collection
The order collections will also sorts a collection by using the order by clause for the results fetched.
The more the collection, the more efficient of sorting.
Explain The Advantages And Disadvantages Of Detached Objects.
Advantages
• Detached objects passing can be done across layers upto the presentation layer without using Data Transfer Objects.
• At the time of using long transactions by the user which needs long think-time, it is suggested to split these transactions into some transactions. The detached objects get modified apart from the transaction scope which then can be re-attached to a new transaction.
Disadvantages
• The usage of detached objects are cumbersome and cryptic. It is suggested not to be cluttered with the session, if possible.
• It is recommended to use DataTransferObjects and DomainObjects that is used to maintain separation between the user interfaces and the Service.
What Is Hibernate Query Language (hql)?
Hibernate Query Language is designed for data management using Hibernate technology. It is completely object oriented and hence has notions like inheritance, polymorphism and abstraction. The queries are case-sensitive. This has an exception for Java classes and properties. The query operations are through objects. HQL acts as a bridge between Objects and RDBMS.
Explain The General Flow Of Hibernate Communication With Rdbms.
The general flow of Hibernate communication with RDBMS is
• The Hibernate configuration is to be loaded and creation of configuration object is done. The mapping of all hbm files will be performed automatically.
• Creation of session factory from the configuration object.
• Obtain a session from the session factory.
• Creation of HQL Query .
• Execution of the query in order to get the list of containing java objects.
Explain The Role Of Session Interface In Hibernate.
• In hibernate, the Session interface wraps a JDBC connection, holds a mandatory (first-level) cache of persistent objects, used when navigating the object graph or looking up objects by identifier and is a factory for Transaction.
• Session session = sessionFactory.openSession();
• The Session interface is the primary interface used by Hibernate applications.
• It is a single-threaded, short-lived object representing a conversation between the application and the persistent store.
• It allows you to create query objects to retrieve persistent objects.
Post a Comment