-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Steps to upgrading from 2x to 3x
PostPosted: Wed Sep 07, 2005 11:02 am 
Beginner
Beginner

Joined: Tue Nov 02, 2004 1:34 pm
Posts: 45
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 11:10 am 
Beginner
Beginner

Joined: Tue Nov 02, 2004 1:34 pm
Posts: 45
Forgot a couple of important steps

3d. In your hibernateUtil3 - be sure to specify the new config file: configuration = new Configuration().configure("hibernate3.cfg.xml"); as by defualt it will grab the "hibernate.cfg.xml" which has the 2x libs referenced

5d. in your data services layer, change calls from hibernateUtil to hibernateUtil3

Lee


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.