Hi, I am preparing a Hibernate training. The training will be two days long and targeted at somewhat experienced Java developers with no Hibernate experience.
So what things would you cover / leave out in such a training?
Hi, I am preparing a Hibernate training. The training will be two days long and targeted at somewhat experienced Java developers with no Hibernate experience.
So what things would you cover / leave out in such a training?
So these are my own ideas so far.
Things that I am not so sure about - more complex mappings - Bidirectional, one-to-many, many-to-many, Inheritance, embeddables - customizing hibernate - Dialects, sql-function, event listeners - caching - lazy loading & fetch strategies
I would break it up as follows:
Day 1 - Introduction
What is Hibernate and what problem does it solve? ORM, JDBC complexities, database neutrality blah blah blah
What's the quickest way to see it working? Annotation driven (no scooting about to fiddle with XML), and Spring (for all it's wonderful helpers).
Show 'em a project with a Main class launching a Spring context with log4j installed. Configure the context to read transaction annotations and DTO annotations. Configure the Hibernate properties to create-drop the schema against MySQL or Postgres or whatever is handy on your system and to show SQL in the console log.
Explain that this is just some boilerplate infrastructure work and that they don't need to worry about it at this stage.
Explain how the @Column annotation works then create a DTO to map an Order.
Run up the application and demonstrate the newly created schema
Explain how the @OneToMany annotation works (owner and inverse etc)
Create a new DTO for OrderItem and link it to the Order so that Order 1-* OrderItem.
Run up the application and demonstrate the extra table and relationship.
Inform them that so far no SQL has been written, it's all just meta data.
Explain the concept of the Hibernate Session.
Explain transient, detached and persistent objects with regard to Sessions.
Build a DAO, based on the Spring HibernateTemplate that will allow a transient Order DTO containing a collection of OrderItem DTOs to be persisted. Then create the transient Order DTO, populate it and send it to the DAO.
Explain that it only takes a single line of code to persist an entire object graph.
Run up the application and show them the result in the database.
Distribute the code and get them to write a unit test to verify the operation of the DAO (look for transient objects becoming persistent through the ID field)
Ask them to add new DTOs for Customer so that Customer 1-* Order 1-* OrderItem
Day 2 - Queries and Transactions
Explain that queries are expressed through the Query or the Criteria API depending on the nature of consuming code (a static Query or a build Criteria).
Explain conjunction and disjunction and joins and map to inner and outer joins.
Explain that HQL is concerned with object relationships and then delegates creation of SQL. Add a method to the DAO to perform a Query based on each API.
Run up the application and demonstrate the query working and what SQL is created.
Explain that transactions are commonly placed away from DAOs and tend to live in services.
Create a service that has the Order DAO injected and give it a @Transaction annotation. Turn on debugging in log4j to observe the transaction messages.
Distribute the code and get them to update the unit test to verify the operation of the DAO to include the results of the query and pre-populating the database with Customers, Orders and OrderItems.
Come up with a variety of queries that need to be implemented.