A very brief introduction

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

Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
M1G Introduction to Database Development 1. Databases and Database Design.
Session-02.
Session-01. Hibernate Framework ? Why we use Hibernate ?
Phil Brewster  One of the first steps – identify the proper data types  Decide how data (in columns) should be stored and used.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
UNIT-V The MVC architecture and Struts Framework.
Hibernatification! Roadmap for Migrating from Plain Old SQL on JDBC to JPA on Hibernate Duke Banerjee Senior Developer, DrillingInfo.com.
Object Oriented Databases by Adam Stevenson. Object Databases Became commercially popular in mid 1990’s Became commercially popular in mid 1990’s You.
CSCI 6962: Server-side Design and Programming
JDBC Java Database Connectivity. What is an RDBMS? Relational database management system. There are other kinds of DBMS. Access is a GUI on a JET RBDMS.
CSE3310: Web training A JumpStart for Project.
NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27
COLD FUSION Deepak Sethi. What is it…. Cold fusion is a complete web application server mainly used for developing e-business applications. It allows.
M1G Introduction to Database Development 6. Building Applications.
Seminar on. Overview Hibernate. What is it? Hibernate. How does it work? Hibernate Tools.
Computer Science 101 Database Concepts. Database Collection of related data Models real world “universe” Reflects changes Specific purposes and audience.
12-CRS-0106 REVISED 8 FEB 2013 CSG2H3 Object Oriented Programming.
CS 157B: Database Management Systems II February 6 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
JDBC Java and Databases. RHS – SOC 2 JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
COMU114: Introduction to Database Development 1. Databases and Database Design.
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.
JPA / HIBERNATE CSCI 6370 Nilayan Bhattacharya Sanket Sable.
Course FAQ’s I do not have any knowledge on SQL concepts or Database Testing. Will this course helps me to get through all the concepts? What kind of.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
Fundamentals of MyBATIS
JDBC Java and Databases. SWC – JDBC JDBC – Java DataBase Connectivity An API (i.e. a set of classes and methods), for working with databases in.
Singleton Academy, Pune. Course syllabus Singleton Academy Pune – Course Syllabus1.
In the Name Of Almighty Allah. Java Application Connection To Mysql Created by Hasibullah (Sahibzada) Kabul Computer Science Faculty Afghanistan.
Introduction to ORM Hibernate Hibernate vs JDBC. May 12, 2011 INTRODUCTION TO ORM ORM is a programming technique for converting data between relational.
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.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
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.
A Presentation Presentation On JSP On JSP & Online Shopping Cart Online Shopping Cart.
CS520 Web Programming Spring – Web MVC Chengyu Sun California State University, Los Angeles.
HIBERNATE/Java Overview of technology for Hibernate by محمد حسن کاظمی پوران Master : M.M.Nematollahi.
Presented by: K.AMARNATH Ht.no:10841f0045 Guided by: T.Suneetha.
COMP 430 Intro. to Database Systems SQL from application code.
Best 3 Software Development Languages. Hibernate Training Hibernate is a high-performance object-relational mapping tool and query service. Hibernate.
Fundamental of Databases
DEPTT. OF COMP. SC & APPLICATIONS
Chengyu Sun California State University, Los Angeles
Introduction to Dynamic Web Programming
JDBC Database Management Database connectivity
PGT(CS) ,KV JHAGRAKHAND
Web Technologies IT230 Dr Mohamed Habib.
Reflection API, JDBC, Hibernate, RMI
Persistence – Iteration 4 Vancouver Bootcamp
Play Framework: Introduction
Server Concepts Dr. Charles W. Kann.
Listing 9.1 ShowLocalConnection.aspx
Entity Framework By: Casey Griffin.
PHP Training at GoLogica in Bangalore
ADO.NET Entity Framework Marcus Tillett
Principles of report writing
ISC440: Web Programming 2 Server-side Scripting PHP 3
Client Access, Queries, Stored Procedures, JDBC
“Introduction To Database and SQL”
Hibernate Bayu Priyambadha, S.Kom.
CS5220 Advanced Topics in Web Programming Spring – Web MVC
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Tutorial 6 PHP & MySQL Li Xu
CS4961 Software Design Laboratory Understand Aquila Backend
Chengyu Sun California State University, Los Angeles
Lecuter-1.
Presentation transcript:

A very brief introduction Hibernate A very brief introduction

Topics to discuss Overview Database Basics & RDBMS JDBC ORM Hibernate

Overview: Where are we? Our web project consists of : A bunch of static design files (such as HTML, CSS) A bunch of java classes that implement logical procedures One part of these logical procedures is to manage Users. Hence: We need some memory somewhere in our server computer to add Users as they sign up.

Database: our “somewhere” A database has a set of tables Each table consists of a number of columns Databases are NOT necessarily within our project Databases even are NOT necessarily within our server computer So now that we have this database provided, how can we use it?

SQL: Structured Query Language SQL is a special-purpose programming language Its “special purpose” is to make the communication with databases possible. It is a programming language; therefore it has a special syntax Now that we “made communication possible”, let’s get right down to business.

RDBMS: Relational Database Management System An RDBMS is a tool to manage relational databases There are a bunch of RDBMSs out there: Oracle Database Microsoft SQL Server MySQL (Oracle Corporation) … We will use MySQL since it is free and available (surprisingly!)

Let’s do a little SQL coding to learn: MySQL Example Let’s do a little SQL coding to learn: Creating users Showing databases Adding tables Making a query

Back to our project a JAVA DATABASE CONNECTOR! We saw how to make databases using SQL codes with the help of MySQL. But how can we set our project (java classes) to manage projects? We still don’t know. Seems like we need something to connect java to our database … Something like… a JAVA DATABASE CONNECTOR!

JDBC: Java Database Connector A JDBC is just a bunch of code that knows what we still don’t know! We import it to our project And now we can make SQL statements and interact with our databases in our java code Let’s use JDBC in action. We are going to make a simple java class that connects to our database.

JDBC Problems We have been able to connect to database and make queries. But every time we want to update a table, we have to make same SQL statements. If a bad guy makes a bad move instead of signing up? We have to handle those guys too We are using OOP, while MySQL is based on relational tables. We have to worry about it too What if there was some kind of mapping between our java objects and our relational tables? Something like…

Object-Relational Mapping The purpose of ORM is to interact with database as we write our code. ORM is between server and JDBC.

So how do we map each class to a table? Hibernate Framework Hibernate is an ORM Framework for java. Like JDBC, Hibernate is a set of libraries To use Hibernate, we simply import it to our project classpath So how do we map each class to a table?

Configuring Hibernate The initial configuration of hibernate is set in an xml file The default name for this xml file is hibernate.cfg.xml In hibernate.cfg.xml we specify the RDBMS that we intend to use, the url for the database we want to access, the user from which we want to access database, the password for that user –if required, and a couple of other <property>s

A sample hibernate.cfg.xml <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration SYSTEM "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost/test</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">ezpass</property> <!-- List of XML mapping files --> <mapping class="ameghezi.User" /> </session-factory> </hibernate-configuration>

<mapping> tag <mapping> tag is exactly where we specify the mapping from the class to the table. This mapping can be managed in two ways.

First Way: Resource The first way to specify mapping is to use a resource The code for <mapping> looks like: <mapping resource=“user.hbm.xml" /> A resource is a .xml file (user.hbm.xml in our example) It looks something like:

User.hbm.xml <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name=“User" table=“USER_DETAILS"> <id name=“userName" type=“string" column="id"> <generator class="native"/> </id> <property name=“password" column=“password" type="string"/> </class> </hibernate-mapping>

Second Way: Annotation We use annotation on our entities to let hibernate know they are to be mapped to their corresponding table. <mapping> then looks like: <mapping class=“ameghezi.User" />

Using Hibernate to save an entity in our database An entity is a “stand-alone” object. Our User example is an entity Using Hibernate to store an entity in our database requires: A Session Factory A Session A Transaction And now, Let’s DO IT

Thank you for learning 