gpt4 book ai didi

spring - 使用Grails和Spring Security向用户添加UserProfile。未设置参数#7

转载 作者:行者123 更新时间:2023-12-02 15:29:09 31 4
gpt4 key购买 nike

我在扩展Spring Security User类以包含配置文件类时遇到了麻烦。概要文件类很简单,仅包含一个字符串列表。当我运行应用程序时,抛出以下错误,未设置参数7:

| Error 2014-03-20 22:33:26,751 [localhost-startStop-1] ERROR util.JDBCExceptionReporter  - Parameter "#7" is not set; SQL statement:
insert into user (id, version, account_expired, account_locked, enabled, "password", password_expired, user_profile_id, username) values (null, ?, ?, ?, ?, ?, ?, ?, ?) [90012-173]
| Error 2014-03-20 22:33:26,815 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Hibernate operation: could not insert: [ibm_cd_dashboard.User]; uncategorized SQLException for SQL [insert into user (id, version, account_expired, account_locked, enabled, "password", password_expired, user_profile_id, username) values (null, ?, ?, ?, ?, ?, ?, ?, ?)]; SQL state [90012]; error code [90012]; Parameter "#7" is not set; SQL statement:
insert into user (id, version, account_expired, account_locked, enabled, "password", password_expired, user_profile_id, username) values (null, ?, ?, ?, ?, ?, ?, ?, ?) [90012-173]; nested exception is org.h2.jdbc.JdbcSQLException: Parameter "#7" is not set; SQL statement:
insert into user (id, version, account_expired, account_locked, enabled, "password", password_expired, user_profile_id, username) values (null, ?, ?, ?, ?, ?, ?, ?, ?) [90012-173]
Message: Hibernate operation: could not insert: [ibm_cd_dashboard.User]; uncategorized SQLException for SQL [insert into user (id, version, account_expired, account_locked, enabled, "password", password_expired, user_profile_id, username) values (null, ?, ?, ?, ?, ?, ?, ?, ?)]; SQL state [90012]; error code [90012]; Parameter "#7" is not set; SQL statement:
insert into user (id, version, account_expired, account_locked, enabled, "password", password_expired, user_profile_id, username) values (null, ?, ?, ?, ?, ?, ?, ?, ?) [90012-173]; nested exception is org.h2.jdbc.JdbcSQLException: Parameter "#7" is not set; SQL statement:
insert into user (id, version, account_expired, account_locked, enabled, "password", password_expired, user_profile_id, username) values (null, ?, ?, ?, ?, ?, ?, ?, ?) [90012-173]
Line | Method
->> 28 | ensureSave in BootStrap
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 14 | doCall in BootStrap$_closure1
| 308 | evaluateEnvironmentSpecificBlock in grails.util.Environment
| 301 | executeForEnvironment in ''
| 277 | executeForCurrentEnvironment . . in ''
| 262 | run in java.util.concurrent.FutureTask
| 1145 | runWorker . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run . . . . . . . . . . . . . . in java.lang.Thread

Caused by JdbcSQLException: Parameter "#7" is not set; SQL statement:
insert into user (id, version, account_expired, account_locked, enabled, "password", password_expired, user_profile_id, username) values (null, ?, ?, ?, ?, ?, ?, ?, ?) [90012-173]
->> 331 | getJdbcSQLException in org.h2.message.DbException
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 171 | get in ''
| 148 | get . . . . . . . . . . . . . . in ''
| 80 | checkSet in org.h2.expression.Parameter
| 163 | checkParameters . . . . . . . . in org.h2.command.Prepared
| 78 | update in org.h2.command.CommandContainer
| 235 | executeUpdate . . . . . . . . . in org.h2.command.Command
| 154 | executeUpdateInternal in org.h2.jdbc.JdbcPreparedStatement
| 140 | executeUpdate . . . . . . . . . in ''
| 28 | ensureSave in BootStrap
| 14 | doCall . . . . . . . . . . . . . in BootStrap$_closure1
| 308 | evaluateEnvironmentSpecificBlock in grails.util.Environment
| 301 | executeForEnvironment . . . . . in ''
| 277 | executeForCurrentEnvironment in ''
| 262 | run . . . . . . . . . . . . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
| Error 2014-03-20 22:33:27,071 [Thread-13] ERROR hbm2ddl.SchemaExport - schema export unsuccessful
Message: Database is already closed (to disable automatic closing at VM shutdown, add ";DB_CLOSE_ON_EXIT=FALSE" to the db URL) [90121-173]
Line | Method
->> 331 | getJdbcSQLException in org.h2.message.DbException
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 171 | get in ''
| 148 | get . . . . . . . . in ''
| 137 | get in ''
| 1413 | checkClosed . . . . in org.h2.jdbc.JdbcConnection
| 1388 | checkClosed in ''
| 428 | getAutoCommit . . . in ''
^ 744 | run in java.lang.Thread

用户资料:
class UserProfile {

static hasOne = [user:User]
static belongsTo = User

static constraints = {
}

static mapping = {
}

List<String> projects
}

用户基本上是标准的 Spring 课:
class User {

transient springSecurityService
static hasOne = [userProfile:UserProfile]


String username
String password
boolean enabled = true
boolean accountExpired
boolean accountLocked
boolean passwordExpired

static transients = ['springSecurityService']

static constraints = {
username blank: false, unique: true
password blank: false
userProfile unique:true, nullable: true

}

static mapping = {
password column: '`password`'
}

Set<Role> getAuthorities() {
UserRole.findAllByUser(this).collect { it.role } as Set
}

def beforeInsert() {
encodePassword()
}

def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}

protected void encodePassword() {
password = springSecurityService.encodePassword(password)
}

}

bootstrap :
def init = { servletContext ->
def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true)
def userRole = new Role(authority: 'ROLE_USER').save(flush: true)

def testUser = new User(username: 'me', password: 'password', userProfile: null)
ensureSave(testUser)
testUser.userProfile = new UserProfile(projects: null, version: null, user: testUser)
ensureSave(testUser)

UserRole.create testUser, adminRole, true

assert User.count() == 1
assert Role.count() == 2
assert UserRole.count() == 1
}

def ensureSave(domainObject) {
if(!domainObject.save(flush:true)) {
throw new Exception("not saved successfully: $domainObject");
}
domainObject
}

删除User和UserProfile类之间的关联将使应用程序正常运行。用我还得到的代码“没有设置参数#4”进行测试。任何帮助表示赞赏。

最佳答案

对于非空字段,当您提交空值时,通常会发生这种错误。保存前,请检查域对象中的数据是否为空值。

另外,请从static hasOne = [user:User]中删除Userprofile关联。 belongsTo在这里很好。

关于spring - 使用Grails和Spring Security向用户添加UserProfile。未设置参数#7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22546642/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com