1600 PMP mock questions 1400 CAPM mock questions 800 SCJP 6 mock questions 600 OCAJP 7 mock questions 590 OCPJP 7 mock questions 556 SCWCD 5 mock questions 500 OCEJWCD 6 mock questions pdfDownload (java,struts, hibernet etc)

Spring interview questions

!!! Spring interview questions !!!

How to integrate Spring with Hibernate ?



There are two steps
step 1.
In the bean.xml which is realted to bean factory spring.
<beans>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>org.hsqldb.jdbcDriver</value>
</property>
<property name="url">
<value>jdbc:hsqldb:data/tutorial</value>
</property>
<property name="username">
<value>sa</value>
</property>
<property name="password">
<value></value>
</property>
</bean>
<bean id="factory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="mappingResources">
<list>
<value>Event.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
</props>
</property>
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
<bean id="eventDao" class="EventSpringDao">
<property name="sessionFactory">
<ref bean="factory" />
</property>
</bean>
</beans>

EventSpringDao class has setter and getter method of sessionFactory.

Step 2.

In the EventSpringDao class you can do getSessionFactory().openSession() to access data base.

or
your class you can extend HibernateDaoSupport.
Exmaple:
public EventSpringDao extends HibernateDaoSupport{
public void saveOrUpdate(Event event){
getHibernateTemplate().saveOrUpdate(event);
}

}

Reviews and Comments


PMP, CAPM, PMI is a registered certification mark of the Project Management Institute, Inc

Copyright © www.techfaq360.com 2016


About US | Contact US | Privacy Policy | Terms and Conditions  | Website disclaimer  | Cancellation and Refund Policy  | Shipping & Delivery Policy