Tutorial Home
Hibernate
Advantage of Hibernate over JDBC
Hibernate Setup with an web Application First Hibernate Application Hibernate mapping with Database TABLE Hibernate Data Type-Java Data Type - SQL Data Type mapping One to Many Relation in Hibernate One to Many Relation in Hibernate bi-directional Many to Many Relation in Hibernate HQL: The Hibernate Query Language Criteria Queries Criteria Queries : Equal (eq), Not Equal(ne), Less than (le), greater than (gt),greater than or equal(ge) and Ordering the results Criteria Queries: And OR conditions Hibernate generator to generate id (primary key) prevent concurrent update in Hibernate,slate object updatation in Hibernate,version checking in Hibernate
Struts Model View Controller (MVC) Model View Controller (MVC) Struts Flow-How Struts Works? Struts Tutorial - Struts Setup- First Struts Action class setup Message Resources Validation Framework Validation Framework-client side ForwardAction IncludeAction DispatchAction LookupDispatchAction DynaActionForm DynaActionForm Struts Tutorial - Mutli-click prevention using struts tokens-Prevent Duplicate Submission Logic Iterate Map and List
JSP
JSP Tutorial Introduction to JSP JSP Comments JSP Syntax JSP Scripting Elements :Scriptlet, expression, declaration JSP Directives implicit objects in JSP JSP Actions Introduction to JSP jsp:useBean The jsp:setProperty Action The jsp:getProperty Action Introduction to JSP
Spring
Spring Tutorial
Introduction to Spring Benefits of Using Spring Framework Inversion of Control in Spring Introduction to BeanFactory Dependency Injection in Spring Collections Setter Injection Bean Scopes in Spring Spring IOC Setup Step by Step Bean Lifecycle in Spring ApplicationContext MessageSources in Spring Web Spring MVC framework Developing Your First Spring Web Application Developing Your Second Spring Web Application with Spring Form Developing Your First Spring Web Application with Spring Validation Framework with Code Example Spring integration with Hibernate
Spring Tutorial Step by Step
Spring integration with Hibernate
Spring integration with Hibernate
Steps to Integrate Spring with Hibernate
Step 1. Create SessionFactory
Spring allows you to define resources like a JDBC DataSource or a Hibernate SessionFactory as beans in an application context.
Set up a JDBC DataSource and a Hibernate SessionFactory on top of it.
<beans>
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:hsql://localhost:9001"/>
<property name="username" value="sa"/>
<property name="password" value="sa"/>
</bean>
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<property name="mappingResources">
<list>
<value>emp.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.HSQLDialect
</value>
</property>
</bean>
</beans>
Step 2. Define HibernateTemplate and Create HibernateTemplate
The HibernateTemplate class provides many methods that mirror the methods exposed on the Hibernate Session interface.
Define DAO object and inject Session Factory.
<beans>
<bean id="empDao" class="com.techfaq.EmpDAO">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>
</beans>
EmpDAO.java class
public class EmpDAO { private HibernateTemplate hibernateTemplate; public void setSessionFactory(SessionFactory sessionFactory) { this.hibernateTemplate = new HibernateTemplate(sessionFactory); } public Collection getEmpByDept(String dept) throws DataAccessException { return this.hibernateTemplate.find("from com.bean.Emp e where e.dept=?", dept); } }
OR You can use
Plain Hibernate to access data base.
Define DAO object and inject Session Factory.
<beans>
<bean id="empDao" class="com.techfaq.EmpDAO">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>
</beans>
EmpDAO.java class
public class EmpDAO{ private SessionFactory sessionFactory; public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } public Collection getEmpByDept(String dept) { return this.sessionFactory.getCurrentSession() .createQuery("from com.bean.Emp e where e.dept=?") .setParameter(0, dept) .list(); } }
OR You can use
HibernateDaoSupport.
HibernateDaoSupport base class offers methods to access the current transactional Session.
EmpDAO.java class
public class EmpDAO extends HibernateDaoSupport { public Collection getEmpByDept(String dept) throws DataAccessException, MyException { Session session = getSession(false); try { Query query = session.createQuery("from com.bean.Emp e where e.dept=?"); query.setString(0, dept); List result = query.list(); if (result == null) { throw new MyException("No results."); } return result; } catch (HibernateException ex) { throw convertHibernateAccessException(ex); } } }
The information you are posting should be related to java and ORACLE technology. Not political.