Q1. Should all the mapping files of hibernate have .hbm.xml extension
to work properly?
Ans: No,
having .hbm.xml extension is a convention and not a requirement for hibernate
mapping file names. We can have any extension for these mapping files. But this is the best
practice to follow this extension.
Q2. How do we create session factory in hibernate?
Ans: To create a session factory in hibernate, an object of
configuration is created first which refers to the path of configuration file
and then for that configuration, session factory is created as given in the
example below:
Configuration config = new
Configuration();
config.addResource("myinstance/configuration.hbm.xml");
config.setProperties( System.getProperties() );
SessionFactory sessions = config.buildSessionFactory();
config.addResource("myinstance/configuration.hbm.xml");
config.setProperties( System.getProperties() );
SessionFactory sessions = config.buildSessionFactory();
Q3. What is meant by Method chaining?
Ans: 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();
.addResource(“myinstance/MyConfig.hbm.xml”)
.setProperties( System.getProperties() )
.buildSessionFactory();
Q4. What does hibernate.properties file consist of?
Ans: 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
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
Q5. What should SessionFactory be placed
so that it can be easily accessed?
Ans: 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.
Q6. What are POJOs and what’s their significance?
Ans: 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 than simple java
classes. Use of POJOs instead of simple java classes results in an efficient
and well-constructed code.
Q7. What is ORM metadata?
Ans: 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.
Q8. What’s HQL?
Ans: HQL is the query language used in Hibernate which is an extension of SQL. HQL is very efficient, simple and flexible query language to do various types of operations on relational database without writing complex database queries.
Q9. What are the different types of
property and class mappings?
• Typical and most common
property mapping
<property name=”description” column=”DESCRIPTION” type=”string”/>
Or
<property name=”description” type=”string”>
<column name=”DESCRIPTION”/>
</property>
• Derived properties
<property name=”averageBidAmount” formula=”( select AVG(b.AMOUNT) from BID b
where b.ITEM_ID = ITEM_ID )” type=”big_decimal”/>
• Typical and most common property mapping
<property name=”description” column=”DESCRIPTION” type=”string”/>
• Controlling inserts and updates
<property name=”name” column=”NAME” type=”string”
insert=”false” update=”false”/>
<property name=”description” column=”DESCRIPTION” type=”string”/>
Or
<property name=”description” type=”string”>
<column name=”DESCRIPTION”/>
</property>
• Derived properties
<property name=”averageBidAmount” formula=”( select AVG(b.AMOUNT) from BID b
where b.ITEM_ID = ITEM_ID )” type=”big_decimal”/>
• Typical and most common property mapping
<property name=”description” column=”DESCRIPTION” type=”string”/>
• Controlling inserts and updates
<property name=”name” column=”NAME” type=”string”
insert=”false” update=”false”/>
No comments :
Post a Comment