-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate Tools Versions for Hibernate 2
PostPosted: Fri Aug 03, 2012 5:31 am 
Newbie

Joined: Fri Aug 03, 2012 5:04 am
Posts: 3
Hello:

I was used to work with Hibernate (don't remember version, probably 2) 4 years ago. Now I ended Up in a project which needs to use an old version of Hibernate (Hibernate 2). I want to generate the hbms and POJO form a database, and make it independent of eclipse, so I am trying to use ant tasks.

The problem I am having is that, when the libs downloaded from eclipse Helios, it gives an <code>java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration</code>. Trying to find information about compatibility between HibernateTools and Hibernate prior to Hibernate 3 has been a nightmare, there is no good documentation since HibernateTools was integrated with JBossTools. At least I couldn't find it or understand it.

I googled and searched everywhere (this forum included) without any luck.

The steps to get to this situation were:

1.- I could execute generation from eclipse Helios plugin, but when trying to call buildSessionFactory in the code (using the usual HibernateUtil, with its Interceptor and ThreadLocal) it throws a ClassCastException:

Code:
Initial SessionFactory creation failed. java.lang.ClassCastException
java.lang.ExceptionInInitializerError
   at com.mypackage.persistence.HibernateUtil.buildSessionFactory(HibernateUtil.java:25)
   at com.mypackage.persistence.HibernateUtil.<clinit>(HibernateUtil.java:13)
   at com.mypackage.Test.main(Test.java:18)
Caused by: java.lang.ClassCastException
   at net.sf.hibernate.persister.AbstractEntityPersister.<init>(AbstractEntityPersister.java:689)
   at net.sf.hibernate.persister.EntityPersister.<init>(EntityPersister.java:690)
   at net.sf.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:42)
   at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:137)
   at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:805)
   at com.mypackage.persistence.HibernateUtil.buildSessionFactory(HibernateUtil.java:18)


The line of the Hibernate Source Code where the exception occurs is this one:

Code:
   versionType = (VersionType) model.getVersion().getType();


2.- So I thought the problem could be with the version of the HibernateTool installed within the eclipse or something like that. So the first step was to reverse engineer from ant, making the code generation independent from eclipse. And here is where the ClassNotFoundException occurred. The packages in Hibernate 2 are all net.sf.hibernate... and in Hibernate 3 are org.hibernate... So I guess its a compatibility problem between the HibernateTool version and the HIbernate version (which in my project must be Hibernate 2). I found nowhere to download old versions of HibernateTools prior to 3.

Any clues, documentation or help will be useful.

Thanks.


Top
 Profile  
 
 Post subject: Re: Hibernate Tools Versions for Hibernate 2
PostPosted: Fri Aug 03, 2012 6:02 am 
Senior
Senior

Joined: Tue Aug 04, 2009 7:45 am
Posts: 124
Internal hibernate and hibernate tools libraries are not used when you run you project. In this case only libraries from your project classpath are used.
Was "model.getVersion().getType()" class compiled with the same hibernate-core as you use now? Try to set up breakpoint on the line and check model.getVersion().getType().getClass() is VersionType and model.getVersion().getType().getClass().getClassLoader() is the same as VersionType .class.getClassLoader()


Top
 Profile  
 
 Post subject: Re: Hibernate Tools Versions for Hibernate 2
PostPosted: Fri Aug 03, 2012 9:09 am 
Newbie

Joined: Fri Aug 03, 2012 5:04 am
Posts: 3
Thanks for the fast reply Dmitry.

model.getVersion().getType() return a DateType (which is not a subclass of VersionType)

I found reference to the same problem in that forum: https://hibernate.onjira.com/browse/HBX-633. Unfortunately it appears the for Hibernate 2 there is no custom strategy class for customazing your reverse engineering strategy.

Anyway, that problem had been solved "magicaly", as usual... '¬¬ (I think I just changed the classpath for including the hbm directly instead as part of a path)

Now, even though the hbm is created with the timestamp atribute as a <version> tag instead of a <property> tag, it queries and inserts ok. I'm lost with this, but as it works meanwhile I am trying to solve the generation problem.

The hibernate-tool.jar is the one inside the plugin folder of my eclipse Helios, the same as the jars that it depends on (freemarker.jar jtidy-r8-20060801.jar). The hibernate2.jar is from the official distribution found at http://sourceforge.net/projects/hibernate/files/hibernate2/ (version 2.1.8).

My build.xml is this one:

Code:
<project name="myProyect" default="reveng" basedir=".">

    <property name="entorno" value="DEV"/>

    <property name="project.basedir" value="${basedir}/../../../.."/>

   <property name="conf.dir" value="${basedir}/conf/${entorno}"/>
    <property name="hbm.dir" value="${basedir}/entities"/>
    <property name="src.dir" value="${project.basedir}/src"/>

   <path id="toolslib">
      <path location="${basedir}/lib/hibernate-tools.jar" />
      <path location="${basedir}/lib/freemarker.jar" />
      <path location="${project.basedir}/lib/hibernate2.jar" />
      <path location="${project.basedir}/lib/ojdbc14_g.jar" />
   </path>

   <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"
      classpathref="toolslib" />

    <target name="reveng">
        <echo message="Entorno: ${entorno}" level="info" />
        <echo message="Starting reverse engineering..." level="info" />

   <hibernatetool>
      <jdbcconfiguration
         packagename="com.vodafone.portability.JobsPOE.persistence.generated"
         revengfile="hibernate.reveng.xml" />
      <hbm2hbmxml destdir="${hbm.dir}" />
   </hibernatetool>

        <echo message="Reverse engineering ended." level="info" />
    </target>

</project>


It stills throws the java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

This class does not exists inside hibernate2.jar nor hibernate-tools.jar

The MANIFEST of the hibernate-tools.har says its the 3.4.0.CR2-SNAPSHOT version. So as I'm using hibernate2.jar I guess I am having a hibernate-hibernateTools missmatch version issue. I bet this class should be found in the hibernateX.jar. But as I must use Hibernate 2 I am trying to find older versions of Hibernate Tools but without any success.

Does anyone know where to find previous versions of hibernate-tools and theirs documentation? Or provide me with other kind of clue that could help me?

Thanks!


Top
 Profile  
 
 Post subject: Re: Hibernate Tools Versions for Hibernate 2
PostPosted: Fri Aug 03, 2012 9:18 am 
Senior
Senior

Joined: Tue Aug 04, 2009 7:45 am
Posts: 124
What for are you going to use hibernate-tools? You probably could temporary use hibernate 3 for generation purposes and after all switch to hiberante2 again?


Top
 Profile  
 
 Post subject: Re: Hibernate Tools Versions for Hibernate 2
PostPosted: Mon Aug 06, 2012 3:26 am 
Newbie

Joined: Fri Aug 03, 2012 5:04 am
Posts: 3
Thanks for the Tip!

The point is that the database may change in the future, more while we are still developing. So the generation will probably take place many times. I don't want that Hibernate3 generates code that may be incompatible with the Hibernate2 libraries. May be at the beginning there is no problem, but I don't want a later change when we are running out of time that includes a regeneration and suddenly the new code from the last change is incompatible with Hibernate2.

¿Anybody knows where can I get older versions of Hibernate Tools?

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.