aspose file tools
The moose likes Object Relational Mapping and the fly likes QuerySyntaxException: Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "QuerySyntaxException: "Tablename is not mapped"" Watch "QuerySyntaxException: "Tablename is not mapped"" New topic
Author

QuerySyntaxException: "Tablename is not mapped"

Kai Allard
Greenhorn

Joined: Jul 03, 2007
Posts: 3
Hi,

I am new to hibernate so I have a question (working on eclipse with JBoss Hibernate tools). I used "Hibernate Code Generation..." in order to get the class and mapping files of an existing database.

In order to test if everything worked fine I opened the HQL editor and wrote the select written bellow but I get this exception. The name of the class (Tablename) is case sensitive (I have read of this error).

I looked at the classes and the mapping files (*.hbm.xml) and the table exists as mapping file and as class and it was registered also in the configuration file.

What is my fault?

org.hibernate.hql.ast.QuerySyntaxException: Tablename is not mapped [SELECT id
FROM Tablename
WHERE number = '400']

Thank you very much.
Halcon Guatemala
Ranch Hand

Joined: Sep 06, 2006
Posts: 57
Hi Kai, could you be sure this line is in your hibernate configuration file:

?

Thanks


"La verdadera sabidur�a viene del temor de Dios"
Kai Allard
Greenhorn

Joined: Jul 03, 2007
Posts: 3
Hi,

thank you for your advice.
I have added the line to the config file and refreshed the project to no result, I am afraid. Still the same error.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 8147
    
  52

Hello "KaiAllard"
Welcome to JavaRanch

We are glad to have you here. We have a naming policy at JavaRanch. Your displayed name must consist of a first name (or an initial), a space, and a family name (in that order) and not be obviously fictitious. Please take a moment to change it, which you can do right here.


[My Blog] [JavaRanch Journal]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 8147
    
  52

org.hibernate.hql.ast.QuerySyntaxException: Tablename is not mapped


You will have to mention the mapping in your hibernate.cfg.xml. Can you post the contents of your hibernate.cfg.xml?
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 8147
    
  52

Sebastian, thanks for taking time to change your display name

We need a few more things to be able to figure out what the issue is.

1) The contents of the hbm.xml for that specific class/table that you are trying to query.
2) The code where you are building the SessionFactory
3) The logs when the SessionFactory is being built
4) The entire exception stacktrace that you are seeing.

In the meantime, can you try out the following:

If your hibernate POJO class (lets call it User) is inside the package named myPackage, then try out this HQL


Note that the User is the classname and not the tablename and also the usr.id and usr.number are members of the User class.

[Jaikiran: Edited to remove specific references to tables, on original poster's request]
[ July 04, 2007: Message edited by: Jaikiran Pai ]
Kai Allard
Greenhorn

Joined: Jul 03, 2007
Posts: 3
I am sorry to have bothered you with that question, but as I have asked because I wasn't sure the database I use is not an open source now (maybe later...) so i am not allowed (at this moment) to employ Hibernate tools and "reverse engineering" on it.

So I deleted my posts.

PS: I would be glad if you could also delete any special information concerning the database out of your posts. Thank you very much.
[ July 04, 2007: Message edited by: Sebastian Strempel ]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 8147
    
  52

Originally posted by Sebastian Strempel:
PS: I would be glad if you could also delete any special information concerning the database out of your posts. Thank you very much.


Done.
J Straube
Greenhorn

Joined: Feb 22, 2010
Posts: 1
Hi,

I would guess you miss understood the ejb-ql thing ....

thats your statement:
SELECT id FROM Tablename WHERE number = '400'
I would use that one:
select obj.id from Objectname as obj where number ='400';

means:
the ejb-ql syntax is used with Objects and its attributes, NOT with tablenames or tablecolums at all.
Thats the magic behind the loosely coupled paradigm behind the entity beans.

Cheers Jens
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: QuerySyntaxException: "Tablename is not mapped"
 
Similar Threads
My class is not mapped
Sybase stored proc error
My hibernate generator
An association from the table "dependent" refers to an unmapped class: "Independent"
Help with HQL