Announcement Announcement Module
Collapse
No announcement yet.
About EmbeddedDatabase close method... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • About EmbeddedDatabase close method...

    Hello Guys

    I have created a mini prototype project working with an embedded database..it works fine with XML and annotations
    But I have detected a little situation when I work with JavaConfig..

    According with the documentation

    14.8.3 Creating an embedded database instance programmatically

    It has the follow example

    Code:
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    EmbeddedDatabase db = builder.setType(H2).addScript("my-schema.sql").addScript("my-test-data.sql").build();
    // do stuff against the db (EmbeddedDatabase extends javax.sql.DataSource)
    db.shutdown()
    Same situation in the EmbeddedDatabaseBuilder API

    Code:
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    EmbeddedDatabase db = builder.setType(H2).addScript("schema.sql").addScript("data.sql").build();
    db.shutdown();
    Well I have the follow...

    Code:
    @Bean
    public DataSource dataSource(){
    		
    	EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    		
    	EmbeddedDatabase db = builder.
    				          setType(EmbeddedDatabaseType.HSQL).
    				          addScript("classpath:/com/manuel/jordan/hsql/scripts/hsql-creation-script.sql").
    				          build();
    		
    	db.shutdown();
    	return db;
    }
    When I execute my Main class I get

    Code:
    Exception in thread "main" org.springframework.jdbc.BadSqlGrammarException:
    PreparedStatementCallback; bad SQL grammar 
    [INSERT INTO articulo(id, estado, codigo, descripcion, cantidad, precioVenta) VALUES(?, ?, ?, ?, ?, ?)]; 
    nested exception is java.sql.SQLSyntaxErrorException: 
    user lacks privilege or object not found: ARTICULO
    	at ...
    Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: ARTICULO
    	at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    	at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    	at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
    	at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
    	at org.springframework.jdbc.core.PreparedStatementCreatorFactory$PreparedStatementCreatorImpl.createPreparedStatement(PreparedStatementCreatorFactory.java:245)
    	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:583)
    	... 6 more
    Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: ARTICULO
    	at org.hsqldb.error.Error.error(Unknown Source)
    	at org.hsqldb.error.Error.error(Unknown Source)
    	...
    	... 10 more
    But If I do a simple comment..

    Code:
    @Bean
    public DataSource dataSource(){
    		
    	EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    		
    	EmbeddedDatabase db = builder.
    				           setType(EmbeddedDatabaseType.HSQL).
    				           addScript("classpath:/com/manuel/jordan/hsql/scripts/hsql-creation-script.sql").
    				              build();
    		
    	//db.shutdown();
    	return db;
    }
    all work....

    Therefore why close the DataSource immediately when it is created?
    I could assume it is a bug in the documentation... If Yes I would create a JIRA about this...

    Kind Regards
Working...
X