File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Hibernate getting started Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate getting started" Watch "Hibernate getting started" New topic

Hibernate getting started

Franck McGeough

Joined: Oct 27, 2005
Posts: 26
So, I'm on my 2nd day of looking at Hibernate. I decided to try a real simple example and code from scratch and I'm totally puzzled at the moment. I have a table in sql server with 3 columns. The primary key is an identity column. the other two columns are simple varchar fields. I'm using Microsoft SQL Server.

I can connect to the database, insert rows, update the rows but when I attempt to do a query an exception is thrown in getImportedClassName(). I have a hibernate.cfg.xml that defines that I have one mapping stored in the TestTable.hbm.xml file. My query looks like this :

List items = session.createQuery("from testtable").list();

is there some other configuration thing that I need to twiddle to make this work? Also, are there particular things to read beside the "Hibernate Reference Doc" and "Hibernate In Action" book for people getting started? I'm using Hibernate 3.1. Thanks.
Franck McGeough

Joined: Oct 27, 2005
Posts: 26
The stack trace on the exception is :

at org.hibernate.hql.ast.ASTQueryTranslatorFactory.createQueryTranslator(
at org.hibernate.impl.SessionFactoryImpl.createQueryTranslators(
at org.hibernate.impl.SessionFactoryImpl.getQuery(
at org.hibernate.impl.SessionImpl.getQueries(
at org.hibernate.impl.SessionImpl.list(
at org.hibernate.impl.QueryImpl.list(

I've got the following hibernate related jar's in the classpath :

Stan Sokolov
Ranch Hand

Joined: Apr 13, 2004
Posts: 120

I am not sure that query can be called without select clause

Good luck for yourself.
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518

In Hibernate the select clause is optional so "from mytable" is a valid query.


The class names in Hibernate queries are case sensitive so your query should be "from TestTable" if your class name is TestTable.

What is the actual exception being thrown? The stack trace above is missing the first line that describes the exception.

Finally, Hibernate Quickly is a good book for Hibernate beginners.
Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
In HQL you want to query the domain-object name, not the table name, for example:

If your class is mapped correctly the query will translate this for you.


Franck McGeough

Joined: Oct 27, 2005
Posts: 26
Got it. Thanks, that worked like a charm. Javaranch rocks! I'll get over my kneejerk "lets just code this in OCI/ODBC C/C++" now. h
I agree. Here's the link:
subject: Hibernate getting started
It's not a secret anymore!