views:

137

answers:

1

I have a persistent class Author with two fields: int id, String name.

Problem is that whenever I execute query this way:

Session s = HibernateUtil.getSessionFactory().getCurrentSession();
s.beginTransaction();

Query q = s.createQuery("from Author");
return (Author)q.list().get(0);

It works fine and returns me an Author object with filled fields. But whenever I try to put a condition in my query, for example:

Session s = HibernateUtil.getSessionFactory().getCurrentSession();
s.beginTransaction();

Query q = s.createQuery("from Author a where a.id=41");
return (Author)q.list().get(0);

my application crashes down. This is the top most error that I receive in error stack:

java.lang.reflect.UndeclaredThrowableException
    at $Proxy0.createQuery(Unknown Source)

Please help me, it has taken me more than 3 hours but I am upto no solution yet. Thanks.

+1  A: 

The only thing you need to do is to link all JARs that come with hibernate like:

  antlr.jar
  cglib.jar
  asm.jar
  asm-attrs.jars
  commons-collections.jar
  commons-logging.jar
  hibernate3.jar
  jta.jar
  dom4j.jar
  log4j.jar

and your code should work.

Maras
I just found that (don't know why) I had two versions of antlr.jar in my lib folder. Removed one and now its working. Thanks for your answers.
craftsman