Upgrade from Hibernate 2.x to 3.0
Hibernate 3.0 is not a simple "drop in" upgrade to older versions. There is a list of changes on their website. I'm going to share the steps I've gone through -- your mileage may vary.
The good news is that you can run Hibernate 2.x and 3.0 side by side so you don't have to change your entire application all at once.
1. Right click on your project in Eclipse and choose MyEclipse>Add Hibernate Properties
a. Check version 3
b. Choose new config file, give it new name. You'll need both versions while your app has code running under hibernate 2.x and 3.x
c. For those not using MyEclipse -- just att the new hibernate jar's to your project (I originally wrote this for a MyEclipse audience)
2. Add libs ant-antlr-1.6.3,antlr-2.7.5H3 as they are not installed by MyEclipse...I got them from the hibernate.org download site
3. Copied HibernateUtil.java to HibernateUtil3.java -- as I need both old and new versions to run simultaneously
a. change all net.sf.xxxx to org.hibernate.xxxxx in the import lib section
4. Copy Hibernate.cfg.xml (or if you named it something else, or if you used the .properties) to Hibernate3.cfg.xml
a. remember you need both versions while running 2x and 3x code
b. change "net.sf.xxx" to "org.hibernate.xxxx", as in your database dialect
c. I wasn't sure how to EHCache with version 3, so in the mean time, I just commented that section out of my Hibernate3.cfg.xml
5. Update your data services layer. I have <table>Service.java files for each of my data files
a. replace "import net.sf.hibernate.xxxx" with "import org.hibernate.xxxx"
b. at this point I noticed some of my code didn't compile as there are some changes between 2x and 3x. you'll have to go through
and update your code.
c. Example: Criteria criteria = session.createCriteria(Metric.class);
criteria.add( Expression.ilike("metricNumber",metricNumber));
became: Criteria criteria = session.createCriteria(Metric.class);
criteria.add( Restrictions.ilike("metricNumber",metricNumber));
d. repeat step 5 for each of your data classes. The good thing is that you don't have to break your entire app as you go through the process
6. Interestingly a bug I had in one of my <table>.hbm.xml files I had not discovered, was uncovered when I tried to run with 3.0 -- it seems that 3.0 validates all the sql in you *.hbm.xml files before loading the sessionFactory -- and if it finds an error, it fails to load.
I can't guarantee these steps will be what everyone needs to do...but hopefully I can have helped save some of you some time.
Lee
|