-->
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.  [ 9 posts ] 
Author Message
 Post subject: Standalone Hibernate App in Eclipse woes
PostPosted: Mon Oct 03, 2005 7:39 am 
Newbie

Joined: Fri Sep 30, 2005 5:33 am
Posts: 7
Hi,
I said I should be able to figure out how to get Hibernate to work, but I guess I'll have to take that back.

Hear me, oh Muse, about the wrath of Java, that terrible wrath which caused my application to fail so numerous times, even now.

- I installed Eclipse 3.1 with lots of goodies. Both to see what they could do for me, as well as just to have an IDE.
- I installed Hibernate 3.0
- I added hibernate-tools to Eclipse. Let me ignore that. It didn't work and still doesn't.
- I wrote a small standalone application, using the HibernateUtil class from the reference, a simple POJO class and an Oracle database.
- I created Library entries for Hibernate and Oracle. The first simply contains all jar files in the lib directory (plus hibernate3.jar) and the second the oracle jar file.
- I got a NullPointerException in the logging stuff. End of day one.
- A German Gentleman I found on this forum had this Exception as well, and he was told to try commons-logging-1.0.5. It's in Alpha, but yes, that got rid of the NullPointerException.
- Next I got a timeout... The forums suggested I was trying to use the 2.0 DTD, but no, I correctly specified the 3.0 DTD. Hmmm... I am behind a proxy server, but adding it didn't help.
- Tried copying the DTDs to my classpath, but that didn't work either. Next I redid the DTD URL to become a file reference with an absolute path. That works. (How in hell am I going to distribute this app??? Never mind, let's get it to work first.)
- Next exception: java.lang.IllegalAccessError. Huh? The Factory is trying to instantiate some stuff, generate some code, and it fails.
- The only reference I find in the forums to this exception is from someone who says it is because the classpath is wrong, but it contains all Hibernate jars there are. What more does it want? The log has found my Database, I see it correctly enumerating the installed Oracle options.

Please.. someone? HEEEEEEELP!

Bert Laverman
(appearently an absolute beginner. Let's hope my employer won't find out)

Code:
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.0.5
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.Configuration addResource
INFO: Mapping resource: ClassModel.hbm.xml
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: com.syllogic.asmv2.data.ClassModel -> ClassModel
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing extends queue
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing collection mappings
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing association property references
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Oct 3, 2005 1:11:07 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Oct 3, 2005 1:11:07 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Oct 3, 2005 1:11:07 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Oct 3, 2005 1:11:07 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: oracle.jdbc.OracleDriver at URL: jdbc:oracle:thin:@amaro.syllogic.com:1521:randd
Oct 3, 2005 1:11:07 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=asm, password=****}
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Oracle, version: Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
With the Partitioning option
JServer Release 8.1.7.4.0 - Production
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Oracle JDBC driver, version: 9.2.0.6.0
Oct 3, 2005 1:11:07 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.Oracle9Dialect
Oct 3, 2005 1:11:07 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Oct 3, 2005 1:11:07 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: null
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Oct 3, 2005 1:11:07 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.EhCacheProvider
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Oct 3, 2005 1:11:07 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Initial Session Factory Creation Failed
Exception in thread "main" java.lang.ExceptionInInitializerError
   at com.syllogic.asmv2.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:26)
   at com.syllogic.asmv2.hibernate.Main.main(Main.java:29)
Caused by: java.lang.ExceptionInInitializerError
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
   at com.syllogic.asmv2.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:22)
   ... 1 more
Caused by: net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
   at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:236)
   at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
   at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)
   at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
   at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
   at org.hibernate.impl.SessionFactoryImpl.<clinit>(SessionFactoryImpl.java:321)
   ... 3 more
Caused by: java.lang.reflect.InvocationTargetException
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:373)
   at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:218)
   ... 8 more
Caused by: java.lang.IllegalAccessError: class org.hibernate.impl.SessionFactoryImpl$QueryCacheKeyFactory$$KeyFactoryByCGLIB$$f37b4e4d cannot access its superinterface org.hibernate.impl.SessionFactoryImpl$QueryCacheKeyFactory
   at java.lang.ClassLoader.defineClass1(Native Method)
   at java.lang.ClassLoader.defineClass(Unknown Source)
   ... 14 more


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 9:43 am 
Beginner
Beginner

Joined: Sun Jul 31, 2005 1:23 pm
Posts: 35
I sympahtize with you as I am feeling burned by similar configuration and learning curve issues.

I'm not expert but the obvious guess is you are missing an accessor method or it's private.

Can you post your Java class and mapping file?


Top
 Profile  
 
 Post subject: Re: Standalone Hibernate App in Eclipse woes
PostPosted: Mon Oct 03, 2005 9:54 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
The hibernate dtds are within the hibernate jars so if your app cannot find the dtd's, don't think it is a firewall / internet problem, but do think it is a classpath issue. The dtd's are here within hibernate3.jar

hibernate3.jar\org\hibernate

It would be useful if you followed the posting guidelines, and posted all the suggested bits to help us resolve your problem for you.

_________________
On the information super B road


Top
 Profile  
 
 Post subject: Re: Standalone Hibernate App in Eclipse woes
PostPosted: Mon Oct 03, 2005 10:33 am 
Newbie

Joined: Fri Sep 30, 2005 5:33 am
Posts: 7
Quote:
The hibernate dtds are within the hibernate jars so if your app cannot find the dtd's, don't think it is a firewall / internet problem, but do think it is a classpath issue. The dtd's are here within hibernate3.jar

hibernate3.jar\org\hibernate

It would be useful if you followed the posting guidelines, and posted all the suggested bits to help us resolve your problem for you.

I didn't do that bad. Practically all the info was there. Just missed a decimal in the Hibernate version and some pieces of XML. However, I agree completely this looks like a CLASSPATH issue. Problem is, AFAIK I have everything in there. It looks like Eclipse isn't doing what I think I'm telling it to do. I don't know what else I can do here.
I guess my biggest frustration is that the Hibernate documentation expects you to work with "Ant by Hand". I'm quite willing to build the page telling people how to set up Eclipse or NetBeans for developing Hibernate Applications, but I have to get it working myself first. I'm not the first, am I?

Quote:
Need help with Hibernate? Read this first: http://www.hibernate.org/ForumMailingli ... AskForHelp

Check

Quote:
Hibernate version:

3.0.5 Sorry, forgot that last decimal.

Quote:
Mapping documents:

hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration
    PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "file:///c:/Data/Develop/Java/Applications/HibernateTest/bin/hibernate-configuration-3.0.dtd">
    <!--
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd" -->
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
    <property name="hibernate.connection.url">jdbc:oracle:thin:@myserver:1521:mydb</property>
    <property name="hibernate.connection.username">asm</property>
    <property name="hibernate.connection.password">secret</property>
    <property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>

    <!--  Mappings -->
    <mapping resource="ClassModel.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

ClassModel.hbm.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
   PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "file:///c:/Data/Develop/Java/Applications/HibernateTest/bin/hibernate-mapping-3.0.dtd" >
<!-- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" -->
<hibernate-mapping>
  <class name="com.syllogic.asmv2.data.ClassModel">
    <id name="id" type="long" column="cc_modelid">
      <generator class="hilo">
        <param name="table">id_counter</param>
        <param name="column">componentid</param>
      </generator>
    </id>
    <property name="name" type="string" column="cc_modelname"/>
    <property name="desc" type="string" column="cc_desc"/>
  </class>
</hibernate-mapping>


Quote:
Code between sessionFactory.openSession() and session.close():

Actually, the program doesn't even get to that point, but anyways:
Code:
public class Main
{

  /**
   * @param args
   */
  public static void main(String[] args) {
    try {
      Session s = HibernateUtil.currentSession();
      Transaction tx = s.beginTransaction();
      List result = s.createQuery("from ClassModel").list();
      for (Iterator it = result.iterator(); it.hasNext();) {
        ClassModel cm = (ClassModel)it.next();

        System.err.println("id="+cm.getId()+", name=\""+cm.getName()+"\", desc=\""+cm.getDesc()+"\"");
      }
      tx.commit();
      HibernateUtil.closeSession();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

}

Quite likely this will need debugging, but then again, I haven't even gotten this far.

Quote:
Full stack trace of any exception that occurs:

Check, see the end of the log. That's all I have.

Quote:
Name and version of the database you are using:

Check, it's in the log. Not a problem here though.

Quote:
The generated SQL (show_sql=true):

No SQL generated. Didn't get that far.

Quote:
Debug level Hibernate log excerpt:

Check


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 10:59 am 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Did you just copy the files into a folder and assumed that eclipse added them to the classpath. Eclipse can be a total pain with this. You need to goto Build Path -> Configure Buildpath and then add external jars and choose the necessary jars. You'll then see the jar files correctly showing in the buildpath.

Unless you've already done this and I just misunderstood your description. However, I'd agree that it sounds like a classpath issue and nothing to do with hibernate.


Top
 Profile  
 
 Post subject: Re: Standalone Hibernate App in Eclipse woes. Gotha!
PostPosted: Mon Oct 03, 2005 11:26 am 
Newbie

Joined: Fri Sep 30, 2005 5:33 am
Posts: 7
Quote:
Did you just copy the files into a folder and assumed that eclipse added them to the classpath. Eclipse can be a total pain with this. You need to goto Build Path -> Configure Buildpath and then add external jars and choose the necessary jars. You'll then see the jar files correctly showing in the buildpath.

Unless you've already done this and I just misunderstood your description. However, I'd agree that it sounds like a classpath issue and nothing to do with hibernate.

What I did was define Libraries (Preferences->Java->Build Path->User Libraries) which contain all the appropriate jars. Then I made sure they were included in the project's build path and runtime class path.

Prompted by your remark I remembered a remark by (I think) Lazarus Long: "I hate it when a dumb system tries to be smart". I removed the library and imported all the jars into a lib directory of my project. Then I made sure the jars were in the run path. Still no go. Then I double-checked and saw the Library was still in there. I removed it and presto!

I then found out that the HQL "table" was indeed supposed to be a fully-qualified classname, and my mapping missed the table attribute. Now it works.

I'm going to tempt fate and see if I can get the DTDs back where they belong (i.e. in the JAR). Anybody have a place in the Hibernate website where we can put this information? Or do we consider this "necessary Eclipse learning curve"? Let people dig around for a day? or two? :-/


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 12:16 pm 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
It's just an eclipse thing. I've no idea what Eclipse tries to do with libraries apart from scream, "no I will not work".

I always end up creating an lib dir, annd ing the jar files and then configuring the build path.

You could always add it to the wiki.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 03, 2005 4:00 pm 
Beginner
Beginner

Joined: Wed Jul 13, 2005 2:18 pm
Posts: 44
This all gets even more fun when you've got multiple developers working on a web application making use of Hibernate (and other libraries) ;) You need to be a little creative in coming up with a project layout that you can stick in version control while still giving developers some flexibility in their environment set up.

Our current project actually consists of four Eclipse projects, each in source control. One for all Domain objects (which includes hibernate mapping files, and facade classes which handle the hibernate session stuff), one for the presentation layer (a web app using Echo2), a Util project containing in-house helper code, and a Dependencies project (the Eclipse project type is Simple, not Java) holding the proper versions of all our dependencies, in the form of .jar files.

The Domain and Util projects get built into jar files and copied to the WEB-INF/lib folder of the webapp project automagically by Eclipse, thanks to a custom builder we've created. The Domain and Util build paths reference jars in the Dependencies project relative to an Eclipse classpath variable which points to the workspace location on disk (it's up to each developer to set this variable up prior to checking out projects in a workspace - lets us put our workspaces where we want to without breaking everything). Dependencies which we aren't building from source are just copied from the Dependencies project once, and then checked into version control.

It's not ideal, and I've got some ideas for improvement, but it works for us. The only thing that really bugs me is that Eclipse doesn't realize it when our builders copy new versions of the Domain and Util jars into the webapps project behind its back, so the web app project must be manually refreshed occasionally - and if Tomcat is running when you manually refresh, it really gets ugly, and you may have to copy some files by hand or restart the workspace to get things right.

Using Eclipse 3.1 by the way, which made some definate improvements in the way its project metadata files store info. No more absolute paths! Whoohoo!

_________________
- Matt


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 10:56 pm 
Newbie

Joined: Wed Nov 02, 2005 10:49 pm
Posts: 12
On the Eclipse Run Configuration, don't put hibernate relevant libraries under
Bootstrap Entries" but under "User Entries", the problem will be resolved.


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