1 / 30

Seminar on

Seminar on. Overview. Hibernate. What is it? Hibernate. How does it work? Hibernate Tools. Hibernate. What is it?. Definition. Hibernate is free as open source software

jamuna
Download Presentation

Seminar on

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 • Hibernateis 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. Definition

  7. Creator • Gavin King • gavin@hibernate.org • The author of the book «Hibernate in Action» together withChristian 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. Provides quite simple model (fewer LOC) Rather easy for learning Open source software DBMS independence Own query language (HQL) Benefits

  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 mappingfiles • 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 <hibernate-mapping> <class name=“hello.Message” table=“MESSAGES”> <id name=“id” column=“MESSAGE_ID”> <generator class=“increment”/> (assigned, natural) </id> <property name=“text” column=“MESSAGE_TEXT”/> <many-to-one name=“nextMessage” cascade=“all” column=“NEXT_MESSAGE_ID”/> </class> </hibernate-mapping>

  17. Database settings (.cfg.xml) <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property> <property name="hibernate.connection.url">jdbc:hsqldb:hsql://localhost/ </property> <property name="hibernate.connection.username">sa</property> <property name="dialect">org.hibernate.dialect.HSQLDialect</property> <mapping resource="hello/Message.hbm.xml"/> </session-factory> </hibernate-configuration>

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

  19. Work with objects

  20. Work with objects • Through the SessionHibernate works with a Database • Transaction involves a unite of work with a Database

  21. Work with objects

  22. HibernateTools

  23. Hibernate Tools • 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.HibernateToolTask" 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”

More Related