The Part Time Developer 3: Hibernation Mode

I got probably a good 3-5 hours in this weekend concentrating on working through another Hibernate tutorial, experimenting with the tutorials further, and looking through the documentation. I feel I already have a better understanding of the way things work than I did the last time around. This lazy loading stuff is pretty wild the way it works. For instance, say you’ve got a class that has a collection of objects that is stored in another table. Until you actually attempt to access, it hasn’t actually done a database lookup for that data yet. This is some pretty slick stuff, I may have to dwell into the source to see how it works. Gotta watch out for your session scope though. It took me some messing before I starting getting the whole detached stuff and reconnecting them back to a persistent state. I’m very happy that I’m figuring this stuff out on my own.

One thing that I haven’t found anywhere is what the best practice is for returning a list from a query (ex. .list() ) in Java 1.5+ in regards to generics. For instance if I do
List list = session.createQuery("from Person").list();
I get a warning that I should use a parameterized list. So if I switch it to this, which is how I’d prefer it
List<Person> list = session.createQuery("from Person").list();
it warns me that this is an unchecked conversion. Looking through the Caveat Emptor application, they suppress the unchecked warnings. So I’m guessing that’s the suggested practice. I may go hunting for an open source project that makes use of it to see what someone else does.

My plans from here are to continue looking through the core documentation, start exploring the Caveat Emptor app, and start coming up with my own mapping files for different situations.


Tags: ,

%d bloggers like this: