简体   繁体   中英

how to create a standalone grails app with h2 db by using standalone plugin?

I am using grails standalone plugin to create a standalone grails app but I am getting a jdbc h2 exception. It seems to be that the database is not created at runtime.

How can I solve this issue?

Here the exception

org.h2.jdbc.JdbcSQLException: Table "COMPANY" not found; SQL statement:
select this_.id as id15_0_, this_.version as version15_0_, this_.name as name15_0_ from company this_ limit ? [42102-164]

    at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)

    at org.h2.message.DbException.get(DbException.java:169)

    at org.h2.message.DbException.get(DbException.java:146)

    at org.h2.command.Parser.readTableOrView(Parser.java:4753)

    at org.h2.command.Parser.readTableFilter(Parser.java:1080)

    at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1686)

    at org.h2.command.Parser.parseSelectSimple(Parser.java:1793)

    at org.h2.command.Parser.parseSelectSub(Parser.java:1680)

    at org.h2.command.Parser.parseSelectUnion(Parser.java:1523)

    at org.h2.command.Parser.parseSelect(Parser.java:1511)

    at org.h2.command.Parser.parsePrepared(Parser.java:405)

    at org.h2.command.Parser.parse(Parser.java:279)

    at org.h2.command.Parser.parse(Parser.java:251)

    at org.h2.command.Parser.prepareCommand(Parser.java:217)

    at org.h2.engine.Session.prepareLocal(Session.java:415)

    at org.h2.engine.Session.prepareCommand(Session.java:364)

    at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1121)

    at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:71)

    at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:267)

    at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:281)

    at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:313)

    at grails.orm.PagedResultList.<init>(PagedResultList.java:55)

    at com.kodigon.sensexplorer.survey.CompanyController.list(CompanyController.groovy:19)

    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)

    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)

    at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)

    at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)

    at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)

    at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)

    at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:380)

    at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)

    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

    at java.lang.Thread.run(Thread.java:744)

H2 will create the database, it just might not be creating the schema you're expecting. You can add something the following to your URL in DataSource.groovy:

INIT=CREATE SCHEMA IF NOT EXISTS TEST

So you'd have something like:

url = jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;INIT=CREATE SCHEMA IF NOT EXISTS TEST

While a little bit old it can help others in the future, In my case it was only that there were no changelog included, so after a research

Link that helped a lot to understand the issue I had that look similar how to create a standalone grails app with h2 db by using standalone plugin?

Said that, I created a new one and included the generated migration and it worked like a charm...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM