Sprig+hibernate connection setup
Hi all,
I am krishna and working on spring framework
am doing a application in spring and hibernate the conncetion setup is as follows,
I have created 3 xml files - applicationcontext.xml and smartseries.xml and hibernate.cfg.xml
apllication context.xml is as follows,
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate.Hibernate TransactionManager">
<property name="sessionFactory"><ref local="sessionFactory"/> </property>
</bean>
<bean id="sltDAOHibernate" class="slt.dao.SLTDAOHibernate">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate.Hibernate Template">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="sltDAO" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="transactionManager"/>
</property>
<property name="target"><ref bean ="sltDAOHibernate"/> </property>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="set*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
</beans>
and smartseries.xml is as follows,
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="messageSource" class="org.springframework.context.support.Resourc eBundleMessageSource">
<property name="basename"><value>smartseriesMessages</value></property>
</bean>
<bean id="errorController" class="error.ErrorController"/>
<bean id="indexController" class="index.IndexController" >
<property name="admindao"><ref bean="smartseriesDAO"/></property>
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/error.htm">errorController</prop>
<prop key="/index.htm">indexController</prop>
</props>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.Resour ceBundleViewResolver">
<property name="basename"><value>smartseriesViews</value></property>
</bean>
</beans>
and hibernate.cfg.xml is as follows,
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="myeclipse.connection.profile">sltstagingfina l</property>
<property name="connection.url">application url</property>
<property name="connection.username">edb</property>
<property name="connection.password">edb</property>
<property name="connection.driver_class">com.edb.Driver</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDia lect</property>
<property name="connection.release_mode">on_close</property>
<mapping resource="admin/aaa.hbm.xml"></mapping>
</session-factory>
</hibernate-configuration>
More over i am able to connect to database and perform all the database operations
by calling a java class in which i write the methods and connect to database.
this is as follows,
public class smartseriesDAOHibernate extends HibernateDaoSupport implements SltDAO {
String url = "some application url";
String DBusername= "edb";
String DBpassword= "edb";
public boolean getDeleteParentOrgunit(long orgunitid)
{
/*code for calling a stored procedure*/
CallableStatement cs=null;
Connection con=null;
List lst=new ArrayList();
Session session=null;
ResultSet rs=null;
PreparedStatement pstmt = null;
boolean delstatus=false;
long porgunitid =0;
try{
con = DriverManager.getConnection(url,DBusername,DBpassw ord);
Statement st=con.createStatement();
String evquery="select pk_organizationManager.sp_deleteParentOrganization ("+orgunitid+") from dual";
rs = st.executeQuery(evquery);
while(rs.next())
{
delstatus = rs.getBoolean(1);
}
return delstatus;
}
catch(Exception e)
{
}
finally
{
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
}
}
return delstatus;
}
}
By calling such methods in my java controller i am able to perform database operations
So kindly suggest me whether this application setup is correct or not whether i am
going in the right track or not? Or do i need to change my database setup kindly give suggestions
regarding this.
Any help regarding this would be appreciated.
-Thanks
krishna