Announcement Announcement Module
No announcement yet.
Sprig+hibernate connection setup Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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" "">

    <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
    <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>

    <bean id="transactionManager" class="org.springframework.orm.hibernate.Hibernate TransactionManager">
    <property name="sessionFactory"><ref local="sessionFactory"/> </property>

    <bean id="sltDAOHibernate" class="slt.dao.SLTDAOHibernate">
    <property name="sessionFactory"><ref local="sessionFactory"/></property>

    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate.Hibernate Template">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>

    <bean id="sltDAO" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager">
    <ref local="transactionManager"/>
    <property name="target"><ref bean ="sltDAOHibernate"/> </property>
    <property name="transactionAttributes">
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="remove*">PROPAGATION_REQUIRED</prop>
    <prop key="set*">PROPAGATION_REQUIRED</prop>

    and smartseries.xml is as follows,

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "">


    <bean id="messageSource" class=" eBundleMessageSource">
    <property name="basename"><value>smartseriesMessages</value></property>

    <bean id="errorController" class="error.ErrorController"/>

    <bean id="indexController" class="index.IndexController" >
    <property name="admindao"><ref bean="smartseriesDAO"/></property>

    <bean id="urlMapping" class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <prop key="/error.htm">errorController</prop>
    <prop key="/index.htm">indexController</prop>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.Resour ceBundleViewResolver">
    <property name="basename"><value>smartseriesViews</value></property>


    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"

    <!-- Generated by MyEclipse Hibernate Tools. -->

    <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>



    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;
    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);

    delstatus = rs.getBoolean(1);


    return delstatus;

    catch(Exception e)

    try {
    } 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.

  • #2
    I would have a look at the example applications that ship with Spring.
    Last edited by karldmoore; Aug 29th, 2007, 12:07 PM.