porg.hibernate.JDBCException: Error during import script execution

Hibernate JIRA | Chris Bedford | 7 years ago
  1. 0

    I have a very easily reproducible case that demonstrates this: I have a schema initialization script that i keep in import.sql. When I run the script with the contents of import.sql like this, SchemaExport finishes up with no complaint. (note all statements are on one line, with no newlines introduced for readability). *** import.sql - each statement on one lines - no spanning lines **** drop table UserLastNameHistory if exists; create table UserLastNameHistory ( id INTEGER GENERATED BY DEFAULT AS IDENTITY, userid bigint not null, prevLastName varchar(255), newLastName varchar(255), primary key (id) ) ; drop table User if exists; create table User (id bigint not null, firstName varchar(255), lastName varchar(255), primary key (id)) ; create trigger UserLastNameHistoryTrigger after update on User referencing new row as NEWER old row as OLDER FOR EACH ROW insert into UserLastNameHistory ( userid , prevLastName, newLastName) values (id, OLDER.lastName, NEWER.lastName) ; *****end: import.sql ************************* Then when i introduce some newlines for readability I get the stack trace listed in Stack Trace, below. SchemaExport fails to complete. Note when i run the exact statements (with newlines) in a sql tool like squirrel it all runs fine. *** import.sql - same content : newlines introduced for readability **** drop table UserLastNameHistory if exists; create table UserLastNameHistory ( id INTEGER GENERATED BY DEFAULT AS IDENTITY, userid bigint not null, prevLastName varchar(255), newLastName varchar(255), primary key (id) ) ; drop table User if exists; create table User (id bigint not null, firstName varchar(255), lastName varchar(255), primary key (id)) ; *****end: import.sql ************************* I have attached a very simple project that reproduces this issue. to run it unzip it, go to top level directory and type mvn test Stack Trace p1785 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - schema export unsuccessful porg.hibernate.JDBCException: Error during import script execution at org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:258) at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:192) at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:311) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713) at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:204) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:242) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1118) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1085) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:429) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:250) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:247) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:270) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77) at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:182) at org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:152) at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:105) at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:83) at junit.framework.TestCase.runBare(TestCase.java:125) at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127) at org.apache.maven.surefire.Surefire.run(Surefire.java:177) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338) at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997) Caused by: java.sql.SQLException: Unexpected token: in statement [create table UserLastNameHistory (] at org.hsqldb.jdbc.Util.sqlException(Unknown Source) at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source) at org.hsqldb.jdbc.jdbcStatement.execute(Unknown Source) at org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:254) ... 45 more

    Hibernate JIRA | 7 years ago | Chris Bedford
    porg.hibernate.JDBCException: Error during import script execution
  2. 0

    I have a very easily reproducible case that demonstrates this: I have a schema initialization script that i keep in import.sql. When I run the script with the contents of import.sql like this, SchemaExport finishes up with no complaint. (note all statements are on one line, with no newlines introduced for readability). *** import.sql - each statement on one lines - no spanning lines **** drop table UserLastNameHistory if exists; create table UserLastNameHistory ( id INTEGER GENERATED BY DEFAULT AS IDENTITY, userid bigint not null, prevLastName varchar(255), newLastName varchar(255), primary key (id) ) ; drop table User if exists; create table User (id bigint not null, firstName varchar(255), lastName varchar(255), primary key (id)) ; create trigger UserLastNameHistoryTrigger after update on User referencing new row as NEWER old row as OLDER FOR EACH ROW insert into UserLastNameHistory ( userid , prevLastName, newLastName) values (id, OLDER.lastName, NEWER.lastName) ; *****end: import.sql ************************* Then when i introduce some newlines for readability I get the stack trace listed in Stack Trace, below. SchemaExport fails to complete. Note when i run the exact statements (with newlines) in a sql tool like squirrel it all runs fine. *** import.sql - same content : newlines introduced for readability **** drop table UserLastNameHistory if exists; create table UserLastNameHistory ( id INTEGER GENERATED BY DEFAULT AS IDENTITY, userid bigint not null, prevLastName varchar(255), newLastName varchar(255), primary key (id) ) ; drop table User if exists; create table User (id bigint not null, firstName varchar(255), lastName varchar(255), primary key (id)) ; *****end: import.sql ************************* I have attached a very simple project that reproduces this issue. to run it unzip it, go to top level directory and type mvn test Stack Trace p1785 [main] ERROR org.hibernate.tool.hbm2ddl.SchemaExport - schema export unsuccessful porg.hibernate.JDBCException: Error during import script execution at org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:258) at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:192) at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:311) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713) at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:204) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:242) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1118) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1085) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:429) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:250) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:247) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:270) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77) at org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:182) at org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:152) at org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:105) at org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:83) at junit.framework.TestCase.runBare(TestCase.java:125) at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127) at org.apache.maven.surefire.Surefire.run(Surefire.java:177) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338) at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997) Caused by: java.sql.SQLException: Unexpected token: in statement [create table UserLastNameHistory (] at org.hsqldb.jdbc.Util.sqlException(Unknown Source) at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source) at org.hsqldb.jdbc.jdbcStatement.execute(Unknown Source) at org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:254) ... 45 more

    Hibernate JIRA | 7 years ago | Chris Bedford
    porg.hibernate.JDBCException: Error during import script execution
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Got the following error on db start up.

    GitHub | 2 years ago | sztankatt
    java.sql.SQLException: Unexpected token: SEARCHNAME in statement [CREATE TABLE savedsearches ( id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY searchName]
  5. 0

    How to set user classpath precedence when not a mapreduce job?

    Stack Overflow | 3 years ago | user2708246
    java.sql.SQLException: Unexpected token AS, requires ( in statement [create table click as]

    3 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.sql.SQLException

      Unexpected token: in statement [create table UserLastNameHistory (]

      at org.hsqldb.jdbc.Util.sqlException()
    2. HSQLDB
      jdbcStatement.execute
      1. org.hsqldb.jdbc.Util.sqlException(Unknown Source)
      2. org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
      3. org.hsqldb.jdbc.jdbcStatement.execute(Unknown Source)
      3 frames
    3. Hibernate
      SchemaExport.create
      1. org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:254)
      2. org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:192)
      3. org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
      3 frames
    4. Hibernate
      SessionFactoryImpl.<init>
      1. org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:311)
      1 frame
    5. Hibernate
      Configuration.buildSessionFactory
      1. org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
      1 frame
    6. Hibernate EJB
      HibernatePersistence.createContainerEntityManagerFactory
      1. org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:713)
      2. org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127)
      2 frames
    7. Spring ORM
      AbstractEntityManagerFactoryBean.afterPropertiesSet
      1. org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:204)
      2. org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:242)
      2 frames
    8. Spring Beans
      DefaultListableBeanFactory.preInstantiateSingletons
      1. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1118)
      2. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1085)
      3. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:429)
      4. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:250)
      5. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
      6. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:247)
      7. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161)
      8. org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:270)
      8 frames
    9. Spring Context
      ClassPathXmlApplicationContext.<init>
      1. org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)
      2. org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
      3. org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
      3 frames
    10. Spring TestContext
      AbstractSingleSpringContextTests.setUp
      1. org.springframework.test.AbstractSingleSpringContextTests.loadContextLocations(AbstractSingleSpringContextTests.java:182)
      2. org.springframework.test.AbstractSingleSpringContextTests.loadContext(AbstractSingleSpringContextTests.java:152)
      3. org.springframework.test.AbstractSpringContextTests.getContext(AbstractSpringContextTests.java:105)
      4. org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:83)
      4 frames
    11. JUnit
      TestCase.runBare
      1. junit.framework.TestCase.runBare(TestCase.java:125)
      1 frame
    12. Spring TestContext
      ConditionalTestCase.runBare
      1. org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
      1 frame
    13. JUnit
      TestSuite.run
      1. junit.framework.TestResult$1.protect(TestResult.java:106)
      2. junit.framework.TestResult.runProtected(TestResult.java:124)
      3. junit.framework.TestResult.run(TestResult.java:109)
      4. junit.framework.TestCase.run(TestCase.java:118)
      5. junit.framework.TestSuite.runTest(TestSuite.java:208)
      6. junit.framework.TestSuite.run(TestSuite.java:203)
      6 frames
    14. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      4. java.lang.reflect.Method.invoke(Method.java:597)
      4 frames
    15. org.apache.maven
      JUnitTestSet.execute
      1. org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)
      1 frame
    16. SureFire
      Surefire.run
      1. org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
      2. org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
      3. org.apache.maven.surefire.Surefire.run(Surefire.java:177)
      3 frames
    17. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      4. java.lang.reflect.Method.invoke(Method.java:597)
      4 frames
    18. SureFire
      SurefireBooter.main
      1. org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338)
      2. org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997)
      2 frames