facebook

read from a MySQL database table

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

    sirius
    Member

    hi.
    writing to a MySQL database table with the followinf code works without problems:

    
    User user = new User();
             
    user.setUserId("1362");
    user.setUserName("Franz Mustermann");
    user.setUserPassword("test123");
    
    Session session = SessionManager.currentSession();
                 
    Transaction tx = session.beginTransaction();
    session.save(user);
    tx.commit();
    

    but if I want to read the data from the table with the following code, there is an exception:

    
    Session session = SessionManager.currentSession();
    Transaction tx = session.beginTransaction();
    /* The following row will end in an exception:
    Column 'USER1_0_' not found. */
    List user = session.createSQLQuery("select USER_ID, USER_NAME, USER_PASSWORD from user u").addEntity("user", User.class).list();
    tx.commit();
    

    what is my mistake in the code?

    #241907 Reply

    Riyad Kalla
    Member

    why are you writing SQL?

    session.find(“from User”).list();

    NOTE: Find might be deprecated, but try and write your queries in HQL

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: read from a MySQL database table

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