• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Integration Of Springs Framework In Hibernates
 

Integration Of Springs Framework In Hibernates

on

  • 2,722 views

 

Statistics

Views

Total Views
2,722
Views on SlideShare
2,692
Embed Views
30

Actions

Likes
1
Downloads
145
Comments
0

2 Embeds 30

http://letmeknowu.blogspot.com 29
http://raviprakash.typepad.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Integration Of Springs Framework In Hibernates Integration Of Springs Framework In Hibernates Document Transcript

    • By Sunkara Ravi Prakash Software Architect(JAVA & VOIP SIP protocol) AFxisi Inc LLC sunkara.voip.expert@gmail.com
    • Integration of Springs framework in Hibernates.  In this docs tells and explains to the Intermediate developers or programmers in java. Initial, should be understand how the Hibernate ORM framework tool works without integrating with springs.  In Springs there are seven modules. Among them, for hibernate integrating with Spring, before that they have to know the Abstract DAO and Skeleton Design Patterns.  Integration of Springs overcomes unnecessary of SessionFactory and Session objects of the Hibernate, so it has to close the sessions after the used transactions.  Springs will construct the SessionFactory and Session object of Transaction persistence’s. So not to cares about the session closing object in Hibernate.  Some Plug-in’s are they are which can do caring the session objects, If you’re going use the Struts2 with hibernates[which using AbstractGenricDAO Patterns with cacade pattern].  But Springs is a AOP, Bean Factory Object patterns. It Can Integration different DB vendor in single applicationcontext. So Springs care their session objects persistence’s.  In simply words, initializing the objects through xml and reference the objects from xml. The modules invoked in Spring and hibernate are.
    •  Spring Core, which is a IOC, primary component of BeanFactory, an Factory Pattern. The container is then responsible for hooking it all up. That describes in configure file.  Spring DAO, module provides a JDBC-abstraction layer that reduces the need to do tedious JDBC coding and parsing of database-vendor specific error codes. Also, the JDBC package provides a way to do programmatic as well as declarative transaction management, not only for classes implementing special interfaces, but for all your POJOs (plain old Java objects).  Spring ORM, Spring transaction management supports each of these ORM frameworks as well as JDBC.  Spring AOP, which acts interceptor and proxyobject FactoryBean. Org.springframework.jdbc,datasource.DriverManagerDataConfig, This is an initializing to the Driver connection of the database/s. Provides a utility class for easy DataSource access, a PlatformTransactionManager for a single DataSource, and various simple DataSource implementations. In a J2EE container, it is recommended to use a JNDI DataSource provided by the container. Such a DataSource can be exported as a DataSource bean in an ApplicationContext via JndiObjectFactoryBean, for seamless switching to and from a local DataSource bean like this class. Org.springframework.beans.factory.config.PropertiesFacortyBean PropertiesFactoryBean, gets a hibernates properties, By setting the dialect of database. SPI interfaces and configuration-related convenience class for bean factory. Making the properties file from classpath location as properties instance to bean factory. Org.springframework.orm.hibernate.LocalSessionFactoryBean Which returns the SessionFactory of hibernate. In config file, either mappingresource from files or class(annotions ). Reference bean object property of propertyfactorybean to localSessionFactoryBean. Note that switching to JndiObjectFactoryBean is just matter of configured Org,springframework.org.hibernate.hibernateTransactionManager. @param of the sessionfactory object of LocalSessionFactoryBean @returns the Transactionmanager object. Should access bean reference of SessionFactory to HibenateTransactionManager.
    • The above class most do configure in spring context initial to access the Business Objects. For Business Model Object. If Transaction object can use proxy object then using Org,springframework.transaction.inteceptor.transactionprocyFactaryBean Standard AOP proxyFactoryBean. AOP-based solution for declarative transaction demarcation. Its an interceptor for hibernate transaction manager. So application context file will maps the object of the DAO class. In TransactionproxyFactoryBean, has to initialize or pass by objects of sessionfactory and transactionmanager in that class constructor. How to access the Buniness model object to that transactionproxyFactoryBean object. Maps the bean object to the reference of SeesionFactory object of LocalSessionFactoryBean, And By targeting the object of the TranctionproxyFactaryBean object to the targets objects. Every Service implementation of DAO Abstract class or interface class, should set bean object. All beans to reference local transactionproxyFactoryBean for targets and initial sessionfactory bean objects.
    • Spring AOP. Spring orm.hibernate3 Transaction.interceptor.TransactionProxyFactoryBean. LocalSessionFactoryBean, factory bean that create local hibernate SessionFactory instancr. tranactionManager for sinlge hibernate sessionfactory. Spring context. DataSource of drivermanager, this jndiobjectfactorybean Spring DAO. Exception handler to orm Spring Core. Bean.factory.config.ProperrtiesBeanFactory class. Bean name id. Developers has understands the how AOP will calls the Objects of bean name. Before that lets gives a sample applicationcontext.xml of hibernate and springs. <bean id="dataSoruce" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url" value="jdbc:mysql://localhost/springdb"/> <property name="username" value="root"/> <property name="password" value="admin1234"/> </bean> Above bean is a spring context module, for jndiobjectfactorybean Jdbc jndi property, dataSource. <bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="properties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    • <prop key="hibernate.connection.pool_size">10</prop> <prop key="show_sql">false</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.transaction.factory_class"> org.hibernate.transaction.JDBCTransactionFactory </prop> </props> </property> </bean> hibernateProperties bean object, from spring core, for factoryBean object. <bean id="exampleSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBe an"> <property name="dataSource" > <ref local="dataSoruce"/> </property> <property name="hibernateProperties"> <ref bean="hibernateProperties"/> </property> <property name="mappingResources"> <list> <value>Person.hbm.xml</value> </list> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionM anager"> <property name="sessionFactory"><ref bean="exampleSessionFactory"/></property> </bean> ExampleSessionFactory, Spring orm module, which local reference instance to dataSource and bean reference instance to hibernatesproperties. Mapping resouuces just like hibernate mapping hbm files. Transactionmanager, local reference sessionfacory object instance to HibernateTranactionManager. Below Beans are implementing of the business interface. <bean id="personDetails" class="com.in.db.impl.PersonImpls"> <property name="sessionFactory"> <ref local="exampleSessionFactory"/> </property> </bean> personDetails bean object, local reference to the SessionFactory instance. Below one, Transactonal proxy for business object personDetails. <bean id="personsDAO" class="org.springframework.transaction.interceptor.TransactionP roxyFactoryBean"> <property name="transactionManager"> <ref local="transactionManager"/> </property>
    • <property name="target"> <ref local="personDetails"/> </property> <property name="transactionAttributes"> <props> <prop key="addPerson">PROPAGATION_REQUIRED</prop> </props> </property> </bean> Now, for example lets lets do business technique on spring and hibernate, So you want to add the persons details by using spring and hibernate. Let gets the object of application context, by this object, getting beanproperty personDetails to PersonImpl, PersonImpl object model addPerson method will save the person details table. PersonImpl personimpls = (PersonImpl)xmlbeancontext(“personDetails”); Personimpl.addPerson(person); // person is persistence class, Indirectly is call to spring AOP proxy object to get the instances object (implicit object, we called like). Now You Under Standard the simple Spring Hibernate