What are the benefits of ORM and Hibernate?
There are many benefits from these. Out of which
the following are the most important one.
i. Productivity - Hibernate reduces
the burden of developer by providing much of the functionality and let the developer
to concentrate on business logic.
ii. Maintainability - As hibernate provides most of the
functionality, the LOC for the application will be reduced and it is easy to
maintain. By automated object/relational persistence it even reduces the LOC.
iii. Performance - Hand-coded persistence provided greater
performance than automated one. But this is not true all the times. But in
hibernate, it provides more optimization that works all the time there by
increasing the performance. If it is automated persistence then it still
increases the performance.
iv. Vendor independence - Irrespective of the different types
of databases that are there, hibernate provides a much easier way to develop a
cross platform application.
How does hibernate code looks like?
Sessionsession= getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
MyPersistanceClass mpc =
new MyPersistanceClass ("Sample App");
session.save(mpc);
tx.commit();
session.close();
The Session and Transaction are the interfaces provided by hibernate. There are
many other interfaces besides this.
What is a hibernate xml mapping document and how does it look
like?
In order to make most of the things work in
hibernate, usually the information is provided in an xml document. This
document is called as xml mapping document. The document defines, among other
things, how properties of the user defined persistence classes' map to the
columns of the relative tables in database.
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<classname="sample.MyPersistanceClass"table="MyPersitaceTable">
<idname="id"column="MyPerId">
<generatorclass="increment"/>
</id>
<propertyname="text"column="Persistance_message"/>
<many-to-onename="nxtPer"cascade="all"column="NxtPerId"/>
</class>
</hibernate-mapping>
Everything should be included under <hibernate-mapping> tag. This is the
main tag for an xml mapping document.
No comments:
Post a Comment