1) Yes, hibernate makes it very easy to change DB's. For the most part changing one or two lines in a config file will do it.
2) I have found the performance of hibernate to be very good. I have used it with datasets of about 3000+ rows picking about a dozen columns spread out over a few of tables (using joins, but with hibernate I didn't have to actually type in the joins).
3) I haven't used hibernate with stored procedures yet.
Thx for your explanation. Would you mind to briefly explain how Hibernate achieve the database independent? In entity bean with CMP, the EJB container transparently calls the SQL insert/update/delete and persist each entity bean instance to 1 row in the database. So programmer dont need to bother issuing JDBC directly. But this approach also suffers from performance bottleneck as network traffic is required for each row in the table (correct me if I'm wrong).
So how Hibernate get rid of this 1 row 1 network call issue? Sorry my O/R mapping knowledge is limited so not able to image other approach to persist ohjects efficiently.
There are two main ways to query for objects in hibernate. The first is called a 'Criteria' query. With this you basically are creating an object and setting the fields you want to use in the search. You then pass the Criteria object to hibernate and it will translate that into sql.
The second is called hql. hql is a very sql like query language. An example would probably be the easiest to explain.
given the following class:
If you wanted you get all the Person objects out of the db you would write
and pass that to hibernate. If you wanted to get all people named John Smith you would write
from Person as p where p.name='John Smith'
These would both return a List of Person objects. You can also just query for fields (this will often help performance when there are one to many relathionships)
select p.name, p.spouse.name, p.address, p.spouse.address from Person as p
That would return a List of Object's each Object array would have 4 Strings in order of the fields listed in the select. Note that I didn't have to join a Person to it's spouse.
There is also lazy loading to increase performance. Lets say I do
to get all the Person objects. That is going to do one hit to get the list of Persons, then another hit for each person to get the spouse(commonly refered to as the N+1 problem). With lazy loading I could do the same query, but it would only hit the db once to get me all the Person objects. Then if you tried to access a spouse it would go to the db and get just that one spouse.
The hibernate pdf manual is a great resource for all this stuff.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop