Announcement Announcement Module
Collapse
No announcement yet.
hsqldb port problems Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • hsqldb port problems

    When running my app im getting the following error. My program is trying to save a form bean to a table.

    Code:
    org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: Cannot open connection; uncategorized SQLException for SQL []; SQL state [08000]; error code [-80]; socket creation error; nested exception is java.sql.SQLException: socket creation error
    	org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:97)
    	org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:258)
    	org.springframework.orm.hibernate.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:364)
    	org.springframework.orm.hibernate.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:351)
    	org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:369)
    	org.springframework.orm.hibernate.HibernateTemplate.update(HibernateTemplate.java:576)
    	org.springframework.orm.hibernate.HibernateTemplate.update(HibernateTemplate.java:572)
    	src.db.PhotoDaoHib.addPhotoinfo(PhotoDaoHib.java:21)

  • #2
    Is the database up and is configured at the port you are trying to access?
    Besides that, in which mode have you launched hsqldb? It has to match the form of the connect string you use (see the hsqldb reference for details). I remember that I also had problems once when I launched hsqldb in standalone mode, when it should be run in server mode.

    Regards,
    Andreas

    Comment


    • #3
      hi,

      oh i see, i didnt know you need to start this db, i thought it was just a jar file.
      Could you please let me know how i can start the db and create a database and neccessary tables - or does hibernate do that for me?

      Comment


      • #4
        Please refer to the hsqldb documentation for how to use the database. There is a section dedicated to running the database and its modes of operation.

        As of the tables: these you have to create yourself. I think hibernate provides tools for generating a schema from the mapping files, but I have not used this feature yet. Anyway, you could find more information here.

        Regards,
        Andreas

        Comment


        • #5
          thanks for that.

          But now im getting another error which may have something to do with my hibernate code

          Code:
          org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: Could not save object; bad SQL grammar []; nested exception is java.sql.SQLException: Table not found in statement [select next_hi from hibernate_unique_key for update]
          Any ideas? What im trying to do is save an object to the table and im doing it like this in the dao

          Code:
          public void addPhotoinfo(Photo p) {
          		getHibernateTemplate().save(p);
          		
          	}

          Comment


          • #6
            It seems that hibernate expects the "hibernate_unique_key" table to manage its unique keys, as (afaik) hsqldb has no sequences. So you have to create that table or use another id generation strategy. I don't know the expected structure of that table, but that should be documented somewhere.

            Regards,
            Andreas

            Comment


            • #7
              hi,

              here is my hibernate mapping file. I tried changing the id generator (http://www.hibernate.org/hib_docs/re...l/mapping.html) but it didnt work.

              Any ideas on how to fix the error

              Code:
              <?xml version="1.0"?>
              <!DOCTYPE hibernate-mapping
              PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
              "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
              
              <hibernate-mapping>
              	<class name="src.bus.Photo" table="Photo">
              		<id name="id" column="id"
              			type="java.lang.Integer" unsaved-value="-1">
              			<generator class="identity"></generator>
              		</id>
              		<property name="location" column="location" type="string" />
              		<property name="photographer" column="photographer"
              			type="string" />
              		<property name="datetaken" column="datetaken" type="string" />
              		<property name="description" column="description" type="string" />
              	</class>
              </hibernate-mapping>

              Comment


              • #8
                How does "not working" show up? Do you get an exception?

                Regards,
                Andreas

                P.S.: for the "hilo" generator see here. It seems a simple table with one column of appropriate type should be sufficient.

                Comment


                • #9
                  Is column of identity type?

                  Hi waxydock,

                  I have not had trouble when using HSQLDB + Hibernate. I use <generator class="identity"> in my Hibernate mapping and make the column of type identity in my database table. For instance:

                  Code:
                  create table SomeTable(
                       id integer(3) IDENTITY,
                       name char(30));
                  What does your schema look like?

                  -Arthur Loder

                  Comment


                  • #10
                    hi,

                    yeap i use the IDENTITY type for my id. Here is my schema

                    Code:
                    Create Table Photo (
                    	id integer identity Primary key,
                    	location varchar(25) NOT NULL,
                    	photographer varchar(25) NOT NULL,
                    	datetaken varchar(25) NOT NULL,
                    	description varchar(25) NOT NULL
                    );
                    i also changed my datasource url to the following to match the mode im using hsql
                    Code:
                    jdbc:hsqldb:mem:test
                    and here is my photo bean if it helps
                    Code:
                    package src.bus;
                    
                    import java.io.Serializable;
                    import java.util.Date;
                    
                    public class Photo implements Serializable {
                    	
                    	private int id;
                    	private String location; //where photo was taken
                    	private String photographer; //map to username
                    	private String datetaken;
                    	private String description;
                    	
                    	public String getDatetaken() {
                    		return datetaken;
                    	}
                    	
                    	public void setDatetaken(String datetaken) {
                    		this.datetaken = datetaken;
                    	}
                    	
                    	public String getDescription() {
                    		return description;
                    	}
                    	
                    	public void setDescription(String description) {
                    		this.description = description;
                    	}		
                    	
                    	public String getLocation() {
                    		return location;
                    	}
                    	
                    	public void setLocation(String location) {
                    		this.location = location;
                    	}
                    	
                    	public String getPhotographer() {
                    		return photographer;
                    	}
                    	
                    	public void setPhotographer(String photographer) {
                    		this.photographer = photographer;
                    	}
                    
                    	public int getId() {
                    		return id;
                    	}
                    
                    	public void setId(int id) {
                    		this.id = id;
                    	}
                    }
                    complete error
                    Code:
                    exception
                    
                    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: Could not save object; bad SQL grammar []; nested exception is java.sql.SQLException: Table not found in statement [select next_hi from hibernate_unique_key for update]
                    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:406)
                    	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:358)
                    	javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
                    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
                    
                    root cause
                    
                    org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: Could not save object; bad SQL grammar []; nested exception is java.sql.SQLException: Table not found in statement [select next_hi from hibernate_unique_key for update]
                    	org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:224)
                    	org.springframework.orm.hibernate.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:364)
                    	org.springframework.orm.hibernate.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:351)
                    	org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:369)
                    	org.springframework.orm.hibernate.HibernateTemplate.save(HibernateTemplate.java:553)
                    	src.db.PhotoDaoHib.addPhotoinfo(PhotoDaoHib.java:21)
                    	src.bus.PhotoManager.setPhoto(PhotoManager.java:22)
                    	src.controller.PhotoinfoController.onSubmit(PhotoinfoController.java:22)
                    	org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:258)
                    	org.springframework.web.servlet.mvc.AbstractFormController.handleInvalidSubmit(AbstractFormController.java:649)
                    	org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:256)
                    	org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
                    	org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
                    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:723)
                    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:663)
                    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:394)
                    	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:358)
                    	javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
                    	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
                    Last edited by waxydock; Sep 28th, 2006, 05:46 PM.

                    Comment


                    • #11
                      i read somewhere that adding hibernate.hbm2ddl.auto=update would help, as it would auto-create the table. But i dont know how to adding this to my photomapper-servlet.xml file. I tried below, but i get an error

                      any ideas?

                      Code:
                      <beans>
                      	<bean id="multipartResolver"
                      		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
                      		<property name="maxUploadSize" value="1000000000" />
                      	</bean>
                      
                      	<bean id="myDataSource"
                      		class="org.springframework.jdbc.datasource.DriverManagerDataSource"
                      		destroy-method="close">
                      		<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
                      		<property name="url" value="jdbc:hsqldb:mem:test" />
                      		<property name="username" value="sa" />
                      		<property name="password" value="" />
                      	</bean>
                      
                      	<bean id="mySessionFactory"
                      		class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
                      		<property name="dataSource" ref="myDataSource" />
                      		<property name="mappingResources">
                      			<list>
                      				<value>src/db/Photo.hbm.xml</value>
                      			</list>
                      		</property>
                      		<property name="hibernateProperties">
                      			<list>
                      				<value>
                      					hibernate.dialect=org.hibernate.dialect.MySQLDialect
                      				</value>
                      				<value>hibernate.hbm2ddl.auto=update</value>
                      			</list>
                      		</property>
                      	</bean>
                      
                      .....

                      Comment


                      • #12
                        Try create instead of update

                        Hi waxydock,

                        Not sure about your error, but this page has some information: http://forum.hibernate.org/viewtopic.php?t=940659

                        I would try dropping the database and setting hibernate.hbm2ddl.auto=create.

                        -Arthur Loder

                        Comment


                        • #13
                          hmm i think that might work, but im not sure where to put that configuration. If i try to put it as a property in my session factory bean (in myapp-servlet.xml) i get an error. Where should i add it?

                          Comment

                          Working...
                          X