В моем приложении встроен плагин spring security core. После создания с s2-quickstart com.myApplication.secureapp SecAppUser SecAppRole
. Я получил еще 2 класса SecAppRole.groovy
и SecAppUser.groovy
в своем домене. Я также добавил в мой BootStrap.groovy
:Grails - Таблицы не генерируются автоматически с помощью hibernate
class BootStrap {
def init = { servletContext ->
def adminRole = new SecAppRole(authority: 'ROLE_ADMIN').save(flush: true)
def userRole = new SecAppRole(authority: 'ROLE_USER').save(flush: true)
def testUser = new SecAppUser(username: 'admin', enabled: true, password: 'admin')
testUser.save(flush: true)
SecAppUserSecAppRole.create testUser, adminRole, true
assert SecAppUser.count() == 1
assert SecAppRole.count() == 2
assert SecAppUserSecAppRole.count() == 1
}
def destroy = {
}
}
Например SecAppRole.groovy
выглядит следующим образом:
class SecAppRole {
String authority
static mapping = {
cache true
}
static constraints = {
authority blank: false, unique: true
}
}
Однако после добавления кода в файл Bootstrap.groovy
я получаю:
|Loading Grails 2.3.4
|Configuring classpath
.
|Environment set to development
.................................
|Packaging Grails application
Precompiling AST Transformations ...
src C:\Users\GrailsWorkspace\testApplication\target\work\plugins\postgresql-extensions-0.6.1 C:\Users\GrailsWorkspace\testApplication\target\classes
Done precompiling AST Transformations!
..
|Compiling 3 source files
...................................................
|Running Grails application
Configuring Spring Security Core ...
... finished configuring Spring Security Core
Error |
2013-12-15 00:16:25,835 [localhost-startStop-1] ERROR util.JDBCExceptionReporter - FEHLER: Relation »sec_app_role« existiert nicht
Position: 96
Error |
2013-12-15 00:16:25,884 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: could not execute query; SQL [select this_.id as id1_0_, this_.version as version1_0_, this_.authority as authority1_0_ from sec_app_role this_ where this_.authority=?]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
Message: could not execute query; SQL [select this_.id as id1_0_, this_.version as version1_0_, this_.authority as authority1_0_ from sec_app_role this_ where this_.authority=?]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
Line | Method
->> 8 | doCall in BootStrap$_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 308 | evaluateEnvironmentSpecificBlock in grails.util.Environment
| 301 | executeForEnvironment . . . . . in ''
| 277 | executeForCurrentEnvironment in ''
| 334 | innerRun . . . . . . . . . . . . in java.util.concurrent.FutureTask$Sync
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . . . . . . . . . . . . in java.lang.Thread
Caused by SQLGrammarException: could not execute query
->> 8 | doCall in BootStrap$_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 308 | evaluateEnvironmentSpecificBlock in grails.util.Environment
| 301 | executeForEnvironment . . . . . in ''
| 277 | executeForCurrentEnvironment in ''
| 334 | innerRun . . . . . . . . . . . . in java.util.concurrent.FutureTask$Sync
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . . . . . . . . . . . . in java.lang.Thread
Caused by PSQLException: FEHLER: Relation »sec_app_role« existiert nicht
Position: 96
->> 2161 | receiveErrorResponse in org.postgresql.core.v3.QueryExecutorImpl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1890 | processResults in ''
| 255 | execute . . . . . . . . . . . . in ''
| 560 | execute in org.postgresql.jdbc2.AbstractJdbc2Statement
| 417 | executeWithFlags . . . . . . . . in ''
| 302 | executeQuery in ''
| 8 | doCall . . . . . . . . . . . . . in BootStrap$_closure1
| 308 | evaluateEnvironmentSpecificBlock in grails.util.Environment
| 301 | executeForEnvironment . . . . . in ''
| 277 | executeForCurrentEnvironment in ''
| 334 | innerRun . . . . . . . . . . . . in java.util.concurrent.FutureTask$Sync
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . . . . . . . . . . . . in java.lang.Thread
Error |
Forked Grails VM exited with error
I может ясно видеть в моем postgresql db, что таблицы, которые не созданы. Однако, что я пробовал:
- Я создал файл спящего режима с
grails create-hibernate-cfg-xml
. Однако это не меняет мой результат.
Моя проблема заключается в том, что таблицы после создания приложения не создаются. Как указать, что таблицы получают автогенерируемые grails 2
, например, с hibernate
?
Я ценю ваш ответ!
UPDATE
Вот мой DataSource.groovy
:
dataSource {
pooled = true
driverClassName = "org.postgresql.Driver"
dialect = org.hibernate.dialect.PostgreSQLDialect
username = "testApplicationUser"
password = "admin"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
// cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = ""
driverClassName = "org.postgresql.Driver"
dialect = "net.kaleidos.hibernate.PostgresqlExtensionsDialect"
url = "jdbc:postgresql://localhost:5432/testApplication"
username = "testApplicationUser"
password = "admin"
}
}
test {
dataSource {
dbCreate = ""
driverClassName = "org.postgresql.Driver"
dialect = "net.kaleidos.hibernate.PostgresqlExtensionsDialect"
url = "jdbc:postgresql://localhost:5432/testApplication"
username = "testApplicationUser"
password = "admin" }
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=false
validationQuery="SELECT 1"
jdbcInterceptors="ConnectionState"
}
}
}
}
Thx вы очень за ваш ответ! Pls см. Мое обновление;) – mrquad
Добро пожаловать. Вы можете видеть, что ваш dbCreate пуст как в разработке, так и в тестировании. (: –
Thx вы очень за свой ответ! Это работает сейчас;) – mrquad