facebook

Hibernate: cannot get any simple query to work

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #229454 Reply

    bradm
    Member

    While the online tutorial which ADDS a record to a database works without a hitch, any attempt to QUERY the db with Hibernate fails with the same error message: “net.sf.hibernate.exceptionSQLGrammarException: Could not execute query”.

    If I’ve successfully connected to the Pubs db in MS SQLServer using the Database explorer, and if I can ADD rows to the Authors table using the online tutorial, what is there about the following attempt to SEARCH the authors table that is wrong?

    public static void main(String[] args)
    {
    try
    {
    Authors authors = new Authors();
    Session session = SessionManager.currentSession();

    Query q = session.createQuery(“from Authors a”);
    List authorsList = q.list();

    //I tried this syntax too, with the same faulty result
    // List authorsList = session.find(“from Authors a”);
    System.out.println(“Number of Objects: ” + authorsList.size());

    }
    catch(HibernateException e)
    {
    System.out.println(e.toString());
    }
    }

    #229461 Reply

    Riyad Kalla
    Member

    While the online tutorial

    Which tut?

    what is there about the following attempt to SEARCH the authors table that is wrong?

    Please paste the entire stack trace, also can you please post all the information we request in the [URL=http://www.myeclipseide.com/PNphpBB2+file-viewtopic-t-393.html]Posting Guidelines[/URL] thread at the top of this forum? That will give us some context so that we can determine if this is an installation issue, a configuration problem, or a bug. Thanks.

    Additionally, what DB and dialect are you using in your hibernate.cfg.xml file?

    #229469 Reply

    bradm
    Member

    I’m using Eclipse 3.1M6; MyEclipse 3.8.4. The tutorial I’m looking at is at http://myeclipseide.com/enterpriseworkbench/help/index.jsp?topic=/com.genuitec.myeclipse.doc/html/quickstarts/hibernate/index.html

    The errors I get are as follows:

    log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
    log4j:WARN Please initialize the log4j system properly.
    net.sf.hibernate.exception.SQLGrammarException: Could not execute query

    #229473 Reply

    Riyad Kalla
    Member

    Additionally, what DB and dialect are you using in your hibernate.cfg.xml file?

    #229475 Reply

    bradm
    Member

    YIKES I’m an idiot: excuse the interruption (I just found the problem and it’s nobody’s fault but mine)

    #229495 Reply

    Riyad Kalla
    Member

    Could you post the solution? Everyone runs into all different kinds of problems and even the smallest fix can sometimes help or atleast get someone on the right track when they read it.

    Thank you in advance.

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: Hibernate: cannot get any simple query to work

You must be logged in to post in the forum log in