1 / 43

Hibernate & Design Patterns A Practical Overview

Hibernate & Design Patterns A Practical Overview. BSc . Thiago Oliveira Technical Manager Galileo Team Coimbra, April 14 th , 2009. Agenda. Design Patterns Transfer Objects Data Transfer Objects Factories Hibernate Framework Connecting the pieces. PART I Design Patterns & Hibernate.

tevy
Download Presentation

Hibernate & Design Patterns A Practical Overview

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. Hibernate & Design PatternsA Practical Overview BSc. Thiago Oliveira Technical Manager Galileo Team Coimbra, April 14th, 2009

  2. Agenda • Design Patterns • Transfer Objects • Data Transfer Objects • Factories • Hibernate Framework • Connecting the pieces

  3. PART IDesign Patterns & Hibernate

  4. What Are Design Patterns? • In the simplest term, it’s a solution to a design problem in particular field • It’s define the problem, the solution, when apply it and what are the consequences

  5. Transfer Objects

  6. Transfer Objects • A Transfer Object is just a Serializable POJO (Plain Old Java Object) • Also called Persistent POJO or Valuable Object

  7. ResourceTO code Indentify Class “Version”. Calculated Hash using the attributes names and methods signatures. It’s not a random number!

  8. Updatable Transfer Object Strategy

  9. Data Access Objects

  10. Data Access Objects

  11. Data Access Objects • Implement the CRUD operations: • public intinsertResource(…) • public booleandeleteResource(…) • public ResourceTOfindResource(…) • public booleanupdateResource(…) …

  12. DAO – We want more flexibility Abstract Factory Concrete Factory DAO – Implements the operation for a specific Entity

  13. Hibernate Framework • Hibernate is a object/relational mapping (ORM) tool for Java • Hibernates goal is to relieve the developer from 95% of common data persistence related programming task • Last Release: 3.3.1 GA

  14. Hibernate Framework • It provides: • Mapping from Java Objects to Relational Tables • Automatic conversion from Java Types to SQL Types • Data Query and retrieve facilities that can reduce the time effort of development • Sophisticated Query Options you can use pure SQL or HQL (Hibernate Query Language )

  15. Hibernate Framework • It provides: • Transparent Persistence • SQL generation • Support for Transaction

  16. How this magic became true? Through XML Configuration Files and powerful API • Hibernate Conf File (hibernate.cfg.xml) • Mapping Files (myClass.hbm.xml)

  17. A connection configuration filehibernate.cfg.xml

  18. We don’t want to write any single configuration file by hand… • JBoss Tools is a set of plugins for Eclipse for support JBoss and related technology, like Hibernate • The actual stable release is the JBoss Tools 3.0.0.GA, requires Eclipse Ganymede 3.4.2

  19. Hibernate Tools for Hibernate 3.0 • Key Features • Code Generation • Wizards for creation of common Hibernate files • Support auto-completion and syntax highlighting

  20. PART IIConnecting the Pieces

  21. Just Remembering

  22. A Simple ER

  23. A Employee Hibernate Mapping FileEmployeeTO.hbm.xml

  24. Yes, I Know… You want to see code…DepartmentDAO - Interface

  25. Yes, I Know… You want to see code…EmployeeDAO - Interface

  26. Yes, I Know… You want to see code…HbmDepartmentDAO – A concrete DAO

  27. Yes, I Know… You want to see code…HbmDAOFactory – A Concrete Factory

  28. Yes, I Know… You want to see code…DAOFactory – An Abstract Factory

  29. So we got a workspace structure like this…

  30. Ok, That’s beautiful… How do I use it?

  31. A deeper look attestInsertDepartment()

  32. A deeper look attestFindDepartmentById()

  33. A deeper look attestListDepartments()

  34. A deeper look attestFindDepartmentByName()

  35. A deeper look attestUpdateDepartment()

  36. A deeper look attestDeleteDepartment()

  37. Further Reading • More about Hibernate & HSQL • Hibernate Reference Document (http://www.hibernate.org/hib_docs/v3/reference/en/pdf/hibernate_reference.pdf ) • BAUER, Christian; KING, Gavin. Java Persistence with Hibernate. Manning Publications Co: New York, 2007 • More about Data Access Objects • Core J2EE Patterns - Data Access Objects (http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html ) • More about Transfer Objects • Core J2EE Patterns - Transfer Objects (http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html )

  38. Further Reading • More about Junit • Unit testing with JUnit 4.x and EasyMock in Eclipse (http://www.vogella.de/articles/JUnit/article.html ) • Junit 4.x How to (http://pub.admc.com/howtos/junit4x/junit4x.pdf) • More about Hibernate Tools • Hibernate Tools Reference Guide (http://docs.jboss.org/tools/3.0.0.GA/en/hibernatetools/pdf/Hibernatetools_Reference_Guide.pdf)

  39. BSc. Thiago OliveiraTechnical Managerthiagosilvaoliveira@gmail.com

More Related