facebook

Upgrading to Hibernate 3.0

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #236493 Reply

    Hi folks,

    Love the new version of MyEclipse. I see that you’ve added support for hibernate 3. How would I go about upgrading my project from Hibernate 2.x to Hibernate 3?

    TIA,

    Lee

    #236671 Reply

    Riyad Kalla
    Member

    Lee,
    We don’t provide mechanisms to upgrade existing projects, but all you would need to do this manually by upgrading the libraries in your WEB-INF/lib directory, then switching to your navigator view, opening your .myhibernatedata file and adding a line (or changing it if it already existed) that says:
    version=3.0

    #236787 Reply

    @support-rkalla wrote:

    Lee,
    We don’t provide mechanisms to upgrade existing projects, but all you would need to do this manually by upgrading the libraries in your WEB-INF/lib directory, then switching to your navigator view, opening your .myhibernatedata file and adding a line (or changing it if it already existed) that says:
    version=3.0

    It’s more invovled than that. I have it up and running, and I’ll try and post back a “what to do”.

    btw, when I ran the new “add Hibernate 3.0” feature…it failed to install 2 needed libraries:

    ant-antlr-1.6.3
    antlr-2.7.5H3

    Lee

    #236794 Reply

    Here are my steps:

    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

    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));

    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

    #236795 Reply

    Riyad Kalla
    Member

    Fantastic followup Lee, thank you.

    I thought your original question was just “how do I make MyEclipse understand Hibernate 3”.

    #236796 Reply

    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

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: Upgrading to Hibernate 3.0

You must be logged in to post in the forum log in