Using hsqldb, import.sql fails w/ HsqlException: 'unexpected end of statement' if
statements span lines.
--------------------------------------------------------------------------------------------------------
Key: HHH-4817
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4817
Project: Hibernate Core
Issue Type: Bug
Environment: hsqldb -
<artifactId>persistence-api</artifactId> <version>1.0</version>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.2.1.ga</version>
Reporter: Chris Bedford
Priority: Minor
Attachments: jpa-spring-example.tar.gz
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
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira