Presentation is loading. Please wait.

Presentation is loading. Please wait.

Seminar on. Overview Hibernate. What is it? Hibernate. How does it work? Hibernate Tools.

Similar presentations


Presentation on theme: "Seminar on. Overview Hibernate. What is it? Hibernate. How does it work? Hibernate Tools."— Presentation transcript:

1 Seminar on

2 Overview Hibernate. What is it? Hibernate. How does it work? Hibernate Tools

3 Hibernate. What is it?

4 Definition Hibernate is free as open source software Hibernate is an ORM library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database

5 Definition

6

7 Creator Gavin King gavin@hibernate.org The author of the book «Hibernate in Action» together with Christian Bauer

8 The Goals To provide automated & optimized techniques To reduce the time that developers devote to manual coding & make them concentrated more on business logic of their application (25%) To insulate two object models To provide smart fetching & cashing To supply a toolset for development

9 Benefits Provides quite simple model (fewer LOC) Rather easy for learning Open source software DBMS independence Own query language (HQL)

10 Hibernate. How does it work?

11 All you need for start Hibernate distribution (hibernate.org) Database of your choice (hsqldb preferably) SQL tables to hold your persistent objects Java classes to represent that objects in code XML mapping files Configuration file for database connection settings

12 Development strategies Java → Hibernate → Database (top-down) Java ← Hibernate ← Database (bottom-up) Java ← Hibernate → Database (middle-out)

13 Persistent Class package hello; private class Message{ private Long id; private String text; private Message nextMessage; private Message() {} public Message(String text){ this.text = text; } public Long getId(){ return id; }

14 Persistent Class public void setId(Long id){ this.id = id; } public String getText(){ return text; } public void setText(String text){ this.text = text; } public Message getNextMessage(){ return nextMessage; } public void Message(Message nextMessage){ this.nextMessage = nextMessage; } }

15 XML Mapping Tells Hibernate what classes to store in a database and how they relate to Tables and Columns Instead of mappings you can use annotated classes

16 XML Mapping <class name=“hello.Message” table=“MESSAGES”> <id name=“id” column=“MESSAGE_ID”> (assigned, natural) <property name=“text” column=“MESSAGE_TEXT”/> <many-to-one name=“nextMessage” cascade=“all” column=“NEXT_MESSAGE_ID”/>

17 Database settings (.cfg.xml) org.hsqldb.jdbcDriver jdbc:hsqldb:hsql://localhost/ sa org.hibernate.dialect.HSQLDialect

18 Create Database Table Start the database Create a table Now it’s time to see Hibernate in action

19 Work with objects

20 Through the Session Hibernate works with a Database Transaction involves a unite of work with a Database

21 Work with objects

22 Hibernate Tools

23 Toolset for development Makes working with Hibernate much easier Comes with JBoss Tools A part of JBDS Available both as plugin to Eclipse or via Ant tasks

24 Shortly about Ant task To start using Hibernate Tools via Ant define the fallowing task: <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.Hibernate ToolTask" classpathref="project.classpath"/>

25 Hibernate plugin within Eclipse Provides a number of wizards & editors for smart & simpler work with Hibernate Allows to watch the structure of mapping files, execute queries as well as see the results All of these features are available through the Hibernate perspective

26 Development Wizards for creating: Hibernate Configuration File (.cfg.xml) Hibernate XML mapping file (.hbm.xml) Hibernate Console Configuration Hibernate Reverse Engineering (reveng.xml)

27 Code Generation Make use of it when you need to generate one kind of artifacts to another Note : while generating hbm.xml’s, not all conversions might be implemented, thus some hand code editing can be necessary.

28 Editors Hibernate Configuration file editor Hibernate Mapping file editor Reveng.xml editor

29 Hibernate Console Perspective Hibernate Configuration view Mapping Diagram HQL or Hibernate Criteria editors Hibernate query result view & Dynamic SQL translator view Properties View

30 Gratitude Thanks a lot Vitalii Yemialyanchyk & Geraskov Dmitrii Presentation is made with help of the book “Hibernate in action” & “Hibernate Tools Reference Guide”


Download ppt "Seminar on. Overview Hibernate. What is it? Hibernate. How does it work? Hibernate Tools."

Similar presentations


Ads by Google