SpTp CS 4903
Popular in Course
Popular in ComputerScienence
This 6 page Class Notes was uploaded by Miss Alden Shanahan on Tuesday October 20, 2015. The Class Notes belongs to CS 4903 at Southern Polytechnic State University taught by Staff in Fall. Since its upload, it has received 14 views. For similar materials see /class/225458/cs-4903-southern-polytechnic-state-university in ComputerScienence at Southern Polytechnic State University.
Reviews for SpTp
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 10/20/15
How Hibernate Works Hibernate is driven by XML configuration files to con gure data connectivity and map classes to database tables with which it needs to interact These XML les contain database connection speci cs connection pooling details transaction factory settings as well as references to other XML les that describe tables in the database When developer writes code to call API the called API executes necessary g at runtime Rather than use of bytecode processing or code generation Hibernate uses runtime re ection to resolve the persistent properties of a class The persisted objects are de ned in a mapping document which describes the persistent elds and associations as well as subclasses or proxies of the persistent object The mapping documents are compiled at the time of application startup and provide the framework with necessary information for a class At the compiletime of mapping documents a SessionFactory is also created that provides the mechanism for managing persistent classes and the Session interface The Session class provides the interface between the persistent stored data and the application The Session interface wraps a JDBC connection which can be usermanaged or controlled by Hibernate This interface is intended only used by a single threadapplication That means after completing the session application is closed and discarded Hibernate Architecture Unlike other technologies Hibernate provides persistence as a service rather than as a framework It integrates awlessly with various application architectures There are two common recommended architectures can be seen including Hibernate as a persistence layer The following diagram describes the Web twotiered Architecture of Hibernate zrlaer Ardttleuure A ylhunnn ltlbema moment Prune lls xMtMeeulnur muns Hlbemate The above dlagram shows that Hlbemate Mr a t Ll MW 0 To u Wtb rn t t a t A a I t the reeords ean be performed by the Hrbernate on the table of database Hrbernate e persrst JavaBeane used by eervleteJSPern Model Vlew Controller MVC arehrteeture Now the fell ng dlagram desenbes the imam threeruered Arehrteeture of o e at Thea ovedagrams ows hatHrbernatersusrng e atabase and eon guratron datato provlde persrstenee servlces and persrstent objects to e aggllcauon Ton Wlh m t Then w n perform these operaaons Hrbemate arehrteeture has three mam eomponents Cnnneeu39nn Management database eonneetrons Database eonneetron ls the most expenslve part of database eonneetron Transactinn management Transaeaon management servlce provlde the ablllty to the user to exeeute more than one database statements at a time Object relational mapping Object relational mapping is technique of mapping the data representation from an object model to a relational data model This part of the hibernate is used to select insert update and delete the records form the underlying table When we pass an object to a Sessionsave method Hibernate reads the state of the variables of that object and executes the necessary query Hibernate is very good tool as far as object relational mapping is concern but in terms of connection management and transaction management it is lacking in performance and capabilities So usually hibernate is being used with other connection management and transaction management tools For example apache DBCP is used for connection pooling with the Hibernate Hibernate provides a lot of exibility in use It is called quotLitequot architecture when we only uses the object relational mapping component While in quotFull Creamquot architecture all the three component Object Relational mapping Connection Management and Transaction Management are used gtxlt gtxlt gtxlt package roseindiatutoria1hibernate gtxlt gtxlt author Administrator gtxlt public class Contact private String rstName private String lastName private String email private int id public String getEmail return email public void setEmailString email thisemai1 email public String getFirstName return rstName public void setFirstNameString rstName quotgt lthibernatemappinggt ltclass namequotroseindiatut0rialhibernateContactquot tablequotCONTACTquotgt ltid namequotidquot typequotintquot columnquotIDquot gt ltgenerat0r classquotassignedquotgt ltidgt ltpr0perty namequot rstNamequotgt ltcolumn namequotFIRSTNAMEquot gt ltpr0pertygt ltpr0perty namequotlastNamequotgt ltcolumn namequotLASTNAMEquotgt ltpr0pertygt ltpr0perty namequotemailquotgt ltcolumn namequotEMAILquotgt ltpr0pertygt ltclassgt lthibernatemappinggt gtxlt gtllt package roseindiatut0rialhibernate import javaXtransacti0nTransaction import orghibernateSession import orghibernateSessionFactory import orghibernatecfgCon guration author Administrator gtxlt public class HibemateExample param args public static void mainString args TODO Autogenerated method stub Session session null try This step will read hibematecfgXml and prepare hibernate for use SessionFactory sessionFactory new Con gurationocon gurebuildSessionFactoryO form object session sessionFactoryopenSession orghibemateTransaction tr sessionbeginTransaction Create new instance of Contact and set values in it by reading them from System outprintlnquotInserting Recordquot Contact contact new Contact contactsetId3 contactsetFirstNamequotNishaquot contactsetLastNamequotGuptaquot contactsetEmailquotnishu7gptyahoocomquot sessionsavecontact trcommit SystemoutprintlnquotDonequot catchException e System outprintlne getMessageO nally Actual contact insertion will happen at this step session ush sessionclose quotgt lthibernatecon gurationgt ltsessi0nfact0rygt ltpr0perty namequothibernateconnectiondrivericlassquotgtcommysq1jdbcDriverltpr0pertygt ltpr0perty namequothibernateconnectionurlquotgtjdbcmysql1921681052hibernatetut0rialltproperty gt ltpr0perty namequothibernateconnectionusernamequotgtr00tltpr0pertygt ltpr0perty namequothibernateconnectionpasswordquotgtr00tltpr0pertygt ltpr0perty namequothibernateconnectionpoolisizequotgt10ltpr0pertygt ltpr0perty namequotsh0wisqlquotgttrueltpr0pertygt ltpr0perty namequotdialectquotgt0rghibernatedialectMySQLDialectltpr0pertygt ltpr0perty namequothibernatehbm2ddlautoquotgtupdateltpr0pertygt lt Mapping les gt ltmapping resourcequotcontacthbmXmlquotgt ltsessi0nfact0rygt lthibernatecon gurationgt
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'