Spring Database Access Ojitha Kumanayaka Copyright © Virtusa, 2007.

Slides:



Advertisements
Similar presentations
Persistence Jim Briggs 1. 2 Database connectivity: JDBC Java Database Connectivity An API for connecting Java programs (applications, applets and servlets)
Advertisements

Company Confidential 1 © 2005 Nokia DBUpgradeTool_ ppt / / JMa A Database Upgrade Tool Nokia Networks Jukka Maaranen.
Rapid Persistence Layer Development with Hibernate Rapid Persistence Layer Development with Hibernate Tyler Mendenhall E-gineering,
Introduction to the Spring Framework University of Kansas January 2009 This presentation and example application are available at
Distributed Application Development B. Ramamurthy.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
ODBC and JDBC O/R Mapping David Rabinowitz. June 2nd, 2004 Object Oriented Design Course 2 Objects And Databases Most of the applications today are written.
Session-02.
Session-01. Hibernate Framework ? Why we use Hibernate ?
Intro to Spring CJUG - January What is Spring? “The Spring framework provides central transaction control of various objects.” This means that any.
Using Third-Party Frameworks in Building Blocks™ David Ashman Principal Architect, Product Development.
An Introduction to Hibernate Matt Secoske
The Spring Framework A quick overview. The Spring Framework 1. Spring principles: IoC 2. Spring principles: AOP 3. A handful of services 4. A MVC framework.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Montreal CRIM Workshop Data Persistence and Intro to Hibernate.
JUnit testing and Spring How to benefit from Spring support for jUnit during development.
Data Persistence and Object-Relational Mapping Slides by James Brucker, used with his permission 1.
Introduction to JPA Java Persistence API Introduction to JPA.
Hibernatification! Roadmap for Migrating from Plain Old SQL on JDBC to JPA on Hibernate Duke Banerjee Senior Developer, DrillingInfo.com.
Creative Commons Attribution- ShareAlike 2.5 License Sakai Programmer's Café Sakai Oxford Tetra ELF Workshop Sakai Persistence and Intro to Hibernate Aaron.
Training - Day 3 OJB. What is OR Mapping? OR Mapping is the mapping of relational database tables to objects (Java Objects in our case) Many OR Mapping.
NetArchive Suite Workshop 2011 Technical Track - Code refactoring with the Spring Framework.
Agenda What is Hibernate Spring Integration Questions Overview
Introduction to the Spring Framework Rajesh. Spring Mission Statement J2EE should be easier to use OO design is more important than any implementation.
Entity Beans BMP Celsina Bignoli
TDDD05 EJB Lab (Part of slides reused from Mikhail’s) Lu Li
Designing and Developing WS B. Ramamurthy. Plans We will examine the resources available for development of JAX-WS based web services. We need an IDE,
Opus College - overview. OpusCollege - background First project: ICT Capacity Building Mozambican Higher Education Institutions Partners: RUG Groningen,
Spring Framework. Spring Overview Spring is an open source layered Java/J2EE application framework Created by Rod Johnson Based on book “Expert one-on-one.
Spring Data Access By, Srinivas Reddy.S
Stored procedures1 Stored procedures and functions Procedures and functions stored in the database.
Copyright, 1996 © Dale Carnegie & Associates, Inc. Custom SiteSearch Access Client: System Integration at the University of Chicago Tod A. Olson Programmer/Analyst.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Persistence and Hibernate Aaron Zeckoski
© 2011 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 14 Using Relational Databases to Provide Object Persistence (Overview) Modern Database.
JBoss at Work Databases and JBoss Chapter 4 Jeff Schmitt October 26, 2006.
Hibernate 3.0. What is Hibernate Hibernate is a free, open source Java package that makes it easy to work with relational databases. Hibernate makes it.
Spring Framework. About spring Spring is the most popular application development framework for enterprise Java. Millions of developers around the world.
JPA / HIBERNATE CSCI 6370 Nilayan Bhattacharya Sanket Sable.
Persistence – Iteration 4 Vancouver Bootcamp Aaron Zeckoski
Fall CIS 764 Database Systems Engineering L18.2 : Object Relational Mapping … ….Object persistence.
12/6/2015B.Ramamurthy1 Java Database Connectivity B.Ramamurthy.
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions Buenos Aires, June 2009.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
Persistence – Iteration 4 Vancouver Bootcamp Aaron Zeckoski
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
Basics of JDBC Session 14.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions Buenos Aires, June 2009.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
Introduction – ORM, Helloworld Application
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Spring JDBC Simplifying.
Spring JDBC Dima Ionut Daniel. Contents What is Spring JDBC? Overview Spring JDBC Core SQL Exceptions Database Connection Batch Operations Handling BLOB/CLOB.
Fundamentals of MyBATIS
.  A reference model developed for an important use case (Air Job) including UI widgets, controllers, services and DAOs.  After full requirement analysis.
Introduction to ORM Hibernate Hibernate vs JDBC. May 12, 2011 INTRODUCTION TO ORM ORM is a programming technique for converting data between relational.
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions and Spring MVC Buenos Aires, June 2009.
Google Code Libraries Dima Ionut Daniel. Contents What is Google Code? LDAPBeans Object-ldap-mapping Ldap-ODM Bug4j jOOR Rapa jongo Conclusion Bibliography.
CS422 Principles of Database Systems Object-Relational Mapping (ORM) Chengyu Sun California State University, Los Angeles.
CS520 Web Programming Object-Relational Mapping with Hibernate and JPA (I) Chengyu Sun California State University, Los Angeles.
Hibernate Online Training. Introduction to Hibernate Hibernate is a high-performance Object-Relational persistence and query service which takes care.
Hibernate Java Persistence API. What is Persistence Persistence: The continued or prolonged existence of something. Most Applications Achieve Persistence.
HIBERNATE/Java Overview of technology for Hibernate by محمد حسن کاظمی پوران Master : M.M.Nematollahi.
DEPTT. OF COMP. SC & APPLICATIONS
Persistence – Iteration 4 Vancouver Bootcamp
Intro to Spring CJUG - January 2013.
Hibernate Bayu Priyambadha, S.Kom.
Testing a persistence layer
Java Database Connectivity
Developing and testing enterprise Java applications
Enterprise Java Beans.
Chengyu Sun California State University, Los Angeles
Presentation transcript:

Spring Database Access Ojitha Kumanayaka Copyright © Virtusa, 2007.

2 Spring support The Spring Framework integrates with all popular Java data- access frameworks Hibernate 2 and 3 (LGPL) iBATIS (Apache license, partial ORM implementation) Java Data Objects (JDO) 1 and 2 (specifications with commercial and open source implementations) Oracle TopLink (commercial) Apache ObjectRelationalBridge (OJB) (Apache license) EJB3 persistence (specification with commercial and open- source implementations, also called Java Persistence API, or JPA)

3 Effects of Data-Access Leakage Data-access exceptions Database resource management Application design

4 Database Resources Data-access code can show three forms of leakage when dealing with database resources: Resource exhaustion Poor performance Inappropriate connection life cycles reusing a Connection object that was created by another party without closing it.

5 JdbcTemplate JdbcTemplate is a thread-safe data access broker class for working with JDBC Resource exhaustion: All JDBC resources will be properly closed to avoid resource exhaustion. Poor performance: JdbcTemplate uses PreparedStatement for variable SQL statements. Inappropriate connection life cycles: JdbcTemplate will effectively check if an existing Connection object is available for reuse and will reuse it in a thread-safe way. If no such object can be found, it will obtain a Connection object from the DataSource object and close it again. Uninformative exceptions: JdbcTemplate will always translate SQLException to a more specific exception in an exception hierarchy. This exception will contain the SQL statement that caused the error and the full stack trace of the SQLException.

6 JdbcTemplate

7 Using Hibernate templates The main interface for interacting with Hibernate is org.hibernate.Session Provides basic data access functionality such as the ability to save, update, delete, and load objects from the database LocalSessionFactoryBean is a Spring factory bean that produces a local Hibernate SessionFactory instance that draws its mapping metadata from one or more XML mapping files

8 Configure Hibernate 3

9 Choosing a version of Hibernate Spring-Hibernate integration classes needed to import classes from either net.sf.hibernate or org.hibernate, they were presented with the choice of either: Dropping support for Hibernate 2, supporting only Hibernate 3 going forward The Hibernate 2 support is found within the Spring distribution under the org.springframework.orm.hibernate package. Splitting the Spring-Hibernate support code into two strains—one for Hibernate 2 and one for Hibernate 3 Hibernate 3 support under the org.springframework.orm.hibernate3 package

10 Using Hibernate templates Spring’s HibernateTemplate provides an abstract layer over a Hibernate Session. HibernateTemplate’s main responsibility is to simplify the work of opening and closing Hibernate Sessions and to convert Hibernate-specific exceptions to one of the Spring ORM exceptions

11 Hibernate sessionFactory The sessionFactory property takes a reference to an implementation of org.hibernate.SessionFactory. Here you have a few options, depending on how you use Hibernate to map your objects to database tables.

12 Using classic Hibernate mapping files If you are using Hibernate’s classic XML mapping files, you’ll want to use Spring’s LocalSessionFactoryBean Id(INTEGER)Description (varchar(50))

13 Connection to Database (HSQL DB) NOTE: For HSQLDB database run the following script to start on network mode in the c:\hsqldb\data directory. java -cp../lib/hsqldb.jar org.hsqldb.Server -database.0 file:springdb -dbname.0 sales

14 orderDao

15 HibernateDAO

16 Client Application

17 Thank You

18 USA INDIA SRI LANKA UK © V I r t u s a C o r p o r a t i o n "Virtusa" is a trademark of the company and a registered trademark in the EU and In India. "Productization" is a service mark of the company and a registered service mark in the United States. "vRule" is a service mark of the company. For more information please contact