JavaRant Episode 3 - March 22, 2008

Posted on Saturday 22 March 2008

 
icon for podpress  Standard Podcast [27:20m]: Play Now | Play in Popup | Download

Java Rant Episode 3 - Hibernate – March 21st 2008

Show Notes…

Welcome back to the Java Rant podcast

Hibernate

Who is it?

  • JBoss (Redhat)
    • does not require you to use JBoss application server
    • professional open source project
    • JBoss uses Hibernate for their implementation of their JavaEE technology stack

What is it?

  • ORM - Object Relational persistence and query service
  • Lets you program using Object Oriented techniques while interacting with the database.
    • associations
    • inheritance
    • polymorphism
    • composition

How does it work?

  • Setup
    • Configure hibernate to map your POJOs to the db tables and columns
    • Configure hibernate what the relationships of your POJOs are
    • Set up the connections
  • Hibernate has a tool to reverse engineer an existing database schema
  • Using hibernate
    • everything revolves around POJOs and Sessions
    • How to insert
    • How to update
  • Querying
    • SQL
    • Query API
    • HQL

Why use it?

  • Don’t kill a fly with a bazooka!!!!!
  • Drastically cuts down on the development time
  • If you have more than just one person working on the project

Gotchas!

  • Don’t forget that you are working with a database
  • Use the “recommended patterns of usage”

http://www.hibernate.org

Three challenges

Challenges

  • Beginners
    • Create a bean named Person that has two members: first name and last name
    • Don’t forget to do some research to find out what it takes to make a “Java Bean”
    • Create 3 or 4 Person objects, populate their members and add each one to a list.
    • Make sure that the list uses generics so that only a Person object can be added to it
    • Then loop through the list using the extended for loop syntax that was new in Java 5
    • While in the loop, print out the Person’s first and last name

    Intermediate

    • Take the beginner’s challenge and extend it to Hibernate
    • Map the Person bean to a table in your database
    • Once you have inserted a few rows into your Person table, write a query that pulls all people out of the database, loops over the results, and print out their names.
  • Advanced
    • The advanced challenge will show a higher level function of Hibernate.
    • You will make the Person object from the Intermediate challenge, but then you will also create two subclasses, Parent and Child
    • These classes will have the name members from the Person object but they will also have members of their own
    • The Parent class will have a salary member and the Child class will have a schoolName member.
    • Both of these new fields will be added to your database schema but will only be selected when you query for the associated objects.
    • To show that your setup is working, create two queries, one for pulling all Parents and one for pulling all Children. Print out the corresponding members of the objects.

Thanks

  • Jordan Richley for the JavaRant artwork
  • Feedburner.com for the feed redirects
  • Theme Music
    • Opening -”Motherboard” composed by Andy Potterton, published by Perfect Solution Music
    • Closing - “Quick Escape” by Hot Like Cajun from www.hotlikecajun.com
  • Contact
    • http://www.javarant.com
    • http://groups.google.com/group/javarant
    • Call with questions or feedback - 206-350-8705
    • or email comments@javarant.com

Share and Enjoy:
  • Digg
  • del.icio.us
  • Slashdot
  • Technorati
  • description

No comments have been added to this post yet.

Leave a comment

(required)

(required)


Information for comment users
Line and paragraph breaks are implemented automatically. Your e-mail address is never displayed. Please consider what you're posting.

Use the buttons below to customise your comment.


RSS feed for comments on this post | TrackBack URI