• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error in running HQL Query

 
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tired once again building the application..im facing the same problem can anyone suggest me why im getting that error.
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Query should be 'from User'.. Note in User, 'U' should be caps...
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Prasad,
i had done modification what you suggested..i got it..thanks a lot..
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh.. now i understood.. but, you cannot give more than one query..
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
k.i'll try it
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
k..can you provide me information how to insert values in HQL Query0 Editor..is it possible or not..
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any help regarding my post
 
madhuri kunchala
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any help regarding my post.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic