Menu

hibernate-struts error with postgresql

Help
2003-03-12
2003-03-14
  • Isabelle Phan

    Isabelle Phan - 2003-03-12

    desperately trying to get the eg1 hibernate-struts example to work using a posgresql database ...

    the application seems to load the hibernate.properties fine, connects to the postgresql database, but throws an exception when attempting to perform a simple query:

    Hibernate: SELECT user.user_uid as user_uid, user.version as version, user.name as name, user.userName as userName FROM cl_users user WHER
    E (user.userName=? )
    Mar 12, 2003 10:11:25 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
    WARNING: SQL Error: 0, SQLState: null
    Mar 12, 2003 10:11:25 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
    SEVERE: ERROR:  parser: parse error at or near "."

    and later:

    Mar 12, 2003 10:11:25 AM net.sf.hibernate.impl.BatcherImpl closeStatements
    WARNING: Could not close a JDBC statement
    This method is not yet implemented.

    I have used successfully the cirrus.hibernate package (latest version from the hibernate site) with the same postgresql JDBC, so don't understand what is going on.

     
    • Ted Husted

      Ted Husted - 2003-03-12

      The best thing might be to try it with MySQL and confirm that it works as packaged. That would isolate whether its a postgresql issue. If there it is a pg issue, you might need to try porting it back to Hibernate 1.x.

      -Ted.

       
    • Isabelle Phan

      Isabelle Phan - 2003-03-12

      I have installed MySQL locally, created a testeg1 database as root with password mypassword, created the eg1 application tables, put mysql-connector-java-3.0.6-stable-bin.jar in WEB-INF/lib and set the hibernate properties to:

      hibernate.dialect = net.sf.hibernate.dialect.MySQLDialect
      hibernate.connection.driver_class = com.mysql.jdbc.Driver
      hibernate.connection.url = jdbc:mysql://localhost:3306/testeg1?autoReconnect=true
      hibernate.connection.username = root
      hibernate.connection.password = mypassword
      hibernate.connection.pool_size = 20
      hibernate.statement_cache.size = 6
      hibernate.show_sql = true

      and I get:

      Mar 12, 2003 4:07:18 PM net.sf.hibernate.JDBCException <init>
      SEVERE: Cannot open connection
      java.sql.SQLException: Server connection failure during transaction.
      Attemtped reconnect 3 times. Giving up.

      I am running tomcat on the same machine as mysql. I tried removing the port number from the connection url and got the same error.
      On the mysql interactive prompt, I did:
      GRANT ALL ON testeg1.* to root identified by "mypassword"; flush privilege;
      to see if that was the problem, but it still won't connect.

      I've tested a simple servlet to connect to the mysql database and it won't work, so I guess the problem is in the mysql driver or the mysql privileges or both.

      This is desperate.

      Isabelle

       
      • Ted Husted

        Ted Husted - 2003-03-12

        There's a nice control center application for MySQL at their website that you could use to test your installation.

        -Ted.

         
    • Isabelle Phan

      Isabelle Phan - 2003-03-12

      just got it to work: mysql does not recoqnize 'localhost' and I had to put the IP address instead, without the port number :(

      no we are back to the eg1 application and the error I get is:

      javax.servlet.ServletException: Could not save object: Syntax error or access violation,  message from server: "You have an error in your SQL syntax near 'for update' at line 1"

       
    • Isabelle Phan

      Isabelle Phan - 2003-03-12

      OK problem solved:

      mysql will not accept an ID generator of type hilo to create new User or Contact objects!

      the application works if the hibernate mapping files are modified so that the ID generator is set to type 'native' instead of 'hilo'

      alas, the postgresql problem still remains: I've tried setting the ID generator to 'sequence' just for luck, switched to the postgresql hibernate props and still the old error appears:

      javax.servlet.ServletException: Could not execute query: ERROR:  parser: parse error at or near "."

      :(

       
    • Isabelle Phan

      Isabelle Phan - 2003-03-12

      ah, seems like this discussion is going out of sync ;)

      I got the application to sort of half-work on mysql (but still no luck with postgresql) : I can add a user, but only one! If I try entering another user name I get:

      javax.servlet.ServletException: Could not insert: Invalid argument value,  message from server: "Duplicate entry '0' for key 1"

      Isabelle

       
    • Isabelle Phan

      Isabelle Phan - 2003-03-12

      ah, seems like this discussion is going out of sync ;)

      I got the application to sort of half-work on mysql (but still no luck with postgresql) : I can add a user, but only one! If I try entering another user name I get:

      javax.servlet.ServletException: Could not insert: Invalid argument value,  message from server: "Duplicate entry '0' for key 1"

      Isabelle

       
      • Ted Husted

        Ted Husted - 2003-03-12

        Well, you're back to the index issue again. The hilo generator really should work with a current release of MySQL. Try putting that back and running the all target. Ant should recreate the database and include a hibernate_unique_key table to track the ids.

        The native generator  for MySQL might be broken, since you would think the dialect would include the auto-increment flag.

        -Ted.

         
    • Isabelle Phan

      Isabelle Phan - 2003-03-13

      Hello Ted,

      now in all friendliness, I have to ask: you haven't tested this application, have you?

      there is a bug in the main JSP that prevents a User to add more than one Contact: when the list contains one item, the form has 2 "action" for one submit button. This means that this:

      <html:hidden property="action" value="deleteEntry" />

      gets called when the user tries to add a second Contact.

      More annoying: the build file is buggy. Compilation fails because the eg.* classes are not found.

      Anyhow, I thank you nontheless for having posted this: I've learnt a lot. Now this application is running for me. I even got it to work with my postgresql database, using the cirrus.hibernate package (hurrah!).

      best wishes,
      Isabelle

       
    • Isabelle Phan

      Isabelle Phan - 2003-03-14

      I found a bug in the ContactList.java:

      method delete(...) is missing the statement

      egForm.setLoggedIn(false);

      after the User object has been deleted.

      Without this line, when the application tries to delete a user, the servlet throws an org.apache.jasper.JasperException: Cannot find bean user in any scope.
      I presume this is because it tries to execute the JSP code in the <logic:equal> block, with an undefined User bean.

       
      • Ted Husted

        Ted Husted - 2003-03-14

        Thanks. I just made a change so that it redirects back to Welcome to clear everything out.

        About to add the eg2 example.

        -T.

         

Log in to post a comment.