aspose file tools*
The moose likes Object Relational Mapping and the fly likes error in running HQL Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "error in running HQL Query" Watch "error in running HQL Query" New topic
Author

error in running HQL Query

madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi,
i tried the example for Hibernate what is given in Netbeans site..i had done step-by-step what they had said in that site...but im getting error while running HQL Query...here is the error im getting if i had given 'from Film'..the error im getting is

can anyone help me out why im getting that error..im new to Hibernate.

thanks,
madhu.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
i tired once again building the application..im facing the same problem can anyone suggest me why im getting that error.
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 587
    
    3

I guess Film is not mapped, can you please post your hibernate.cfg.xml and .hbm.xml files and the query which you are trying to execute..
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi prasad,
i tried with another db that is present in mysql...eventhough im getting same error..here is the following hibernate xml files.
hibernate.cfg.xml


User.hbm.xml


and im giving query in HQL Query as from user can you check it..and provide me where the code gets wrong.

thanks,madhu.

Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 587
    
    3

Query should be 'from User'.. Note in User, 'U' should be caps...
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi Prasad,
i had done modification what you suggested..i got it..thanks a lot..
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
in HQL Query window....is it restricted to give only one query or more than that...because...i m facing problem if i enter more than one query..if im giving one query..it is working fine..but under that query i had given another query..it is showing error.In HQL Query i had given like this
from User as user where user.name like 'k%'
from User

if i given like this im getting error as


thanks,
madhu.
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 587
    
    3

change the query to from User as user where user.name like 'k%'.. Note no need to from User again at the end.. it should work..
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi Prasad,
i got what you had said...but my doubt is..if i m using more than one query in HQL Query0 it is showing error..here im providing what i had given in HQL Query0 is

if i had given like that in HQL Query Editor..im getting error


is there any restriction or rule that only one query should be there in HQL Query0 Editor.
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 587
    
    3

oh.. now i understood.. but, you cannot give more than one query..
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
k.i think this may be some disadvantage for HQL Query Editor...everytime user need to clear what ever query entered and type new query..thanks for the info you provided...
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
suppose if we want to execute query we need to write coding in Java file or in HQL Query0 Editor can you suggest me..
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 587
    
    3

I suggest to write in java file.. and once in HQL query editor can you check by giving semicolon(;) at the end of each query..
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
i had given semicolon at the end of each query...here is what i coded in HQL Query0 Editor...
from User where id between 1 and 5;
from User;

im getting error as

according to you if i wrote the query in java file...then how we can execute that query...
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 587
    
    3

In the java file, first you need to get the SessionFactory object, open the session and use session.createQuery for excecuting the query..
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
k.i'll try it
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi good morning,
i am facing same problem again...unable to execute my query...i had done using the DB which is present in my system...im getting error as


in HQL Query0 i had given as 'from Emp'...here is the hibernate.cfg.xml

and my Emp.hbm.xml is


yesterday it worked fine...i deleted that file and again i had done freshly...i used NetBeans6.9.1..may i know why im getting that problem.

thanks,
madhu.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
i tried by running the project and Run HQL Query it is getting executed....i had doubt is it necessary to run the project for execution of the query...any help regarding this...
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 587
    
    3

First the project should be executed, then only the hibernate.cfg.xml will be loaded and the necessary mappings will be done.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
k..can you provide me information how to insert values in HQL Query0 Editor..is it possible or not..
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
any help regarding my post
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
i had searched and found the insert command in one of the sites...i applied in my application...but it is showing errors..i used as insert into Test1 (tid, tname) select oo.tid, oo.tname from Test1 oo and im getting error in 'Result' as

and in SQL im getting as 'null'
can anyone suggest me how to do..here is my java file where i wrote insert commandtest.java code


thanks,
madhu.
Jagadeeswara Yaramala
Ranch Hand

Joined: Jul 28, 2010
Posts: 46
I think you have taken the query example from this page.

The given query works fine for me.

You have to notice that the HQL query needs to have the class names (not the database table names and fields).
And also you need to map the entity classes (Test1, BackupStock) to the database tables using proper hibernate mapping files.
Also, the transaction start and end is required for the insert to become effective in the database.


Here is the code snippet that works for me.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
hi good morning,
Jagadeeswara Yaramala wrote
SessionFactory factory = cfg.buildSessionFactory()

can anyone explain what does cfg and BackupStock takes and where should it be declared..and i modified my code as suggested by 'Jagadeeswara Yaramala' eventhough im getting same error..here is my code..


thanks,
madhu.
madhuri kunchala
Ranch Hand

Joined: Mar 30, 2010
Posts: 350
any help regarding my post.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error in running HQL Query