Frameworks| Hibernate| Struts| JSF| JavaFX| Ajax| Spring| DOJO| JDO| iBatis| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Integrating Business Logic Tier and Integration Tier Components 
 

In the business logic tier web have created business objects, business services and now we are going to integrate them using Spring framework.

 

Integrating Business Logic Tier and Integration Tier Components

                          

In the business logic tier web have created business objects, business services and now we are going to integrate them using Spring framework.

Business Objects

In this example we have only one business object the User.

Integration tier components

Hibernate maps the business objects to database using XML configuration file. Following file (User.hbm.xml) is used to map User object with the database.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping auto-import="true" default-lazy="false">

<class 
name="net.roseindia.dao.hibernate.User" 
table="users"
>

<id
name="userId"
type="java.lang.Integer"
column="userId"
>
<generator class="increment" />
</id>

<property
name="userName"
type="java.lang.String"
column="userName"
length="20"
/>
<property
name="userPassword"
type="java.lang.String"
column="userPassword"
length="11"
/>

<property
name="userEmail"
type="java.lang.String"
column="userEmail"
length="30"
/>
<property
name="userAddress"
type="java.lang.String"
column="userAddress"
length="30"
/>

<!-- Associations -->


</class>
</hibernate-mapping>

The HibernateSpringDAO is wired with HibernateTemplate by Spring:

<bean id="HibernateSpringDaoTarget" class="net.roseindia.dao.HibernateSpringDAOImpl">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>

Here is the full code of applicationContext-hibernate.xml file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<!--
- Application context definition for MyFaces, Hibernate and Spring Integration application.
-->
<beans>

<!-- ========================= RESOURCE DEFINITIONS ========================= -->

<!-- Configurer that replaces ${...} placeholders with values from a properties file -->
<!-- (in this case, JDBC-related settings for the dataSource definition below) -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location"><value>/WEB-INF/jdbc.properties</value></property>
</bean>

<!-- Local DataSource that works in any environment -->
<!-- Note that DriverManagerDataSource does not pool; it is not intended for production -->

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"><value>${jdbc.driverClassName}</value></property>
<property name="url"><value>${jdbc.url}</value></property>
<property name="username"><value>${jdbc.username}</value></property>
<property name="password"><value>${jdbc.password}</value></property>

</bean>


<!-- JNDI DataSource for J2EE environments -->
<!--
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>java:comp/env/jdbc/roseindiaDB_local</value></property>
</bean>
-->
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref local="dataSource"/></property>
<property name="mappingResources">
<list>
<value>/net/roseindia/dao/hibernate/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>


<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>


<!-- ========================= BUSINESS OBJECT DEFINITIONS ========================= -->

<!--
Data access object: Hibernate implementation.
-->

<bean id="HibernateSpringDaoTarget" class="net.roseindia.dao.HibernateSpringDAOImpl">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>

<!--
- Transactional proxy for Application's central data access object.
-
- Defines specific transaction attributes with "readOnly" markers,
- which is an optimization that is particularly valuable with Hibernate
- (to suppress unnecessary flush attempts for read-only operations).
-
- Note that in a real-life app with multiple transaction proxies,
- you will probably want to use parent and child bean definitions
- as described in the manual, to reduce duplication.
-->

<bean id="SpringHibernateDao" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref local="transactionManager"/></property>
<property name="target"><ref local="HibernateSpringDaoTarget"/></property>
<property name="transactionAttributes">
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="store*">PROPAGATION_REQUIRED</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

</beans>

This application is supported with full free code. In the next section we will show you how you can download and install it on your computer.

 

                          

» View all related tutorials
Related Tags: java c spring server jsf process io int this log ai js technology with proc e il rating it section

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.