You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Tobb <to...@ifi.uio.no> on 2010/11/27 17:13:17 UTC

Derby + hibernate & import.sql

Hi.

I have a strange problem with Hibernate and Apache Derby. I am trying to
load the import.sql file and run it against a Derby db. My hibernate.cfg.xml
file looks like this:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
	"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
	"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
	
<hibernate-configuration>
	<session-factory>
	<property
name="connection.driver_class">org.apache.derby.jdbc.EmbeddedDriver</property>
	<property
name="connection.url">jdbc:derby:safetyinformation;create=true</property>
	<property name="dialect">org.hibernate.dialect.DerbyDialect</property>
	<property name="hibernate.hbm2ddl.auto">create</property>
	<property name="hibernate.show_sql">true</property>
	</session-factory>
</hibernate-configuration>

When i run the program, it creates a new database called safetyinformation,
so far so good.

But when trying to load import.sql, i get the following error:

org.hibernate.JDBCException: Error during import script execution at line 1
	at
org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:370)
	at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:276)
	at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:219)
	at
org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:370)
	at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1842)
	at
no.simula.modelme.safetyinformation.safetyinformation.App.main(App.java:22)
Caused by: java.sql.SQLSyntaxErrorException: Syntax error: Encountered
"<EOF>" at line 1, column 24.
	at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown
Source)
	at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
	at
org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown
Source)
	at
org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown
Source)
	at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown
Source)
	at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown
Source)
	at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
	at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
	at
org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:366)
	... 5 more
Caused by: java.sql.SQLException: Syntax error: Encountered "<EOF>" at line
1, column 24.
	at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown
Source)
	at
org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown
Source)
	... 14 more
Caused by: ERROR 42X01: Syntax error: Encountered "<EOF>" at line 1, column
24.
	at org.apache.derby.iapi.error.StandardException.newException(Unknown
Source)
	at org.apache.derby.impl.sql.compile.ParserImpl.parseStatement(Unknown
Source)
	at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
	at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
	at
org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown
Source)
	... 8 more

As far as i can tell, this implies some syntax error in the import.sql (had
a few syntax errors, which gave the same message).

The strange thing is, that if i load the import.sql file manually, using
Derbys ij prompt, it loads without error, even in the Derby db created by
Hibernate. 

Is there some part of Hibernates config that i'm missing here?

- Tobb
-- 
View this message in context: http://old.nabble.com/Derby-%2B-hibernate---import.sql-tp30319162p30319162.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.


Re: Derby + hibernate & import.sql

Posted by Tobb <to...@ifi.uio.no>.
>If your import.sql script has a semicolon at the end of each line, try
>taking that semicolon out and see if it affects the behavior.

>Or, if your import.sql script does NOT have a semicolon at the end of each
>line, try adding it back in and see if that helps.

I will try this on monday. I have used semicolons, since that's what Derby
wants in ij, but will try to remove them and see what happens.

>1) Do you think that any part of your script is running? After the failure,
>connect to your database with ij and run "show tables" and the like and see
>if you can figure out how far your script got before it crashed.

>2) Check your derby.log for additional messages and clues. The messages
>in derby.log are often much easier to decipher than the client-side
>messages which are processed by layers and layers of client-side libraries.

>3) Try "binary searching" your script:

The derby.log file does not say much, i think i read somewhere that it some
property needs to be set for it to collect sql-specific errors. I have tried
with only 1 CREATE TABLE statement, and even this did not work, so i do not
think that any part of the script is working. But again, it might be the
semicolon thing. 


-- 
View this message in context: http://old.nabble.com/Derby-%2B-hibernate---import.sql-tp30319162p30320717.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.


Re: Derby + hibernate & import.sql

Posted by Bryan Pendleton <bp...@gmail.com>.
> The strange thing is, that if i load the import.sql file manually, using
> Derbys ij prompt, it loads without error, even in the Derby db created by
> Hibernate.

I'm not Hibernate-fluent, but one thing I often encounter when designing
and testing mechanisms like this is that some import systems want/demand
a semicolon at the end of each line of SQL text in the script, whereas other
import systems can't handle the semi-colon and demand that it be omitted.

If your import.sql script has a semicolon at the end of each line, try
taking that semicolon out and see if it affects the behavior.

Or, if your import.sql script does NOT have a semicolon at the end of each
line, try adding it back in and see if that helps.

If neither solution helps, three other ideas:

1) Do you think that any part of your script is running? After the failure,
connect to your database with ij and run "show tables" and the like and see
if you can figure out how far your script got before it crashed.

2) Check your derby.log for additional messages and clues. The messages
in derby.log are often much easier to decipher than the client-side
messages which are processed by layers and layers of client-side libraries.

3) Try "binary searching" your script:
    a) remove half of the script: does the bug go away?
    b) If the bug went away, restore half of the script you removed and retry
    c) If the bug remains, remove another half of the script and retry
With even a large script, within 5 or 10 runs you'll have narrowed down the
failure to a couple lines at which point it should be obvious.

Hope this helps,

bryan


Re: Derby + hibernate & import.sql

Posted by Tobb <to...@ifi.uio.no>.
Figured it out, appearantly Hibernate does not like line breaks in imported
sql files..
-- 
View this message in context: http://old.nabble.com/Derby-%2B-hibernate---import.sql-tp30319162p30328563.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.