我有一個非常奇怪的問題。我在我的Grails 1.3.6應用程序中安裝了spring-security-core 1.0.1,並根據教程對其進行了配置 - 表格由BootStrap.groovy按順序創建並填充。我正在使用PostgreSQL 8.4數據庫 - 整個事情都在我的本地主機上運行。現在,引導完美的作品,但是當我嘗試登錄我得到一個異常,說Grails spring-security-core插件需要角色表中的用戶名列
org.hibernate.exception.SQLGrammarException: could not execute query
進一步回落:
Caused by: org.postgresql.util.PSQLException: ERROR: Column »username« does not exist
失敗的查詢如下:
select
authrole0_.id as id1_,
authrole0_.version as version1_,
authrole0_.authority as authority1_
from
auth_role authrole0_
where
username=?
這是可以的,因爲auth_role表不應該有用戶名列。但爲什麼Hibernate期望用戶名列,它不應該是一個?
任何線索如何解決這個問題?
我試過兩種不同的hibernate diaclects,沒有任何效果。我注意到表格的映射有點奇怪 - 查找表也是映射的。不幸的是,它在插件的文檔中說我不應該改變它,因爲該插件需要該類。
我的類看起來像:
class AuthUser {
String username
String password
boolean active
boolean accountExpired
boolean accountLocked
boolean passwordExpired
static mapping = {
cache true
username column: '`username`'
password column: '`password`'
}
Set<AuthRole> getAuthorities() {
UserRole.findAllByUser(this).collect { it.role } as Set
}
}
import java.util.Set;
class AuthRole {
String authority
static constraints = {
authority blank: false, unique: true
}
}
import org.apache.commons.lang.builder.HashCodeBuilder
class UserRole implements Serializable {
AuthRole role
AuthUser user
boolean equals(other) {
if (!(other instanceof UserRole)) {
return false
}
other.user?.id == user?.id &&
other.role?.id == role?.id
}
int hashCode() {
def builder = new HashCodeBuilder()
if (role) builder.append(role.id)
if (user) builder.append(user.id)
builder.toHashCode()
}
static UserRole get(long roleId, long userId) {
find 'from UserRole where role.id=:roleId and user.id=:userId',
[roleId: roleId, userId: userId]
}
static UserRole create(AuthRole role, AuthUser user, boolean flush = false) {
new UserRole(role: role, user: user).save(flush: flush, insert: true)
}
static boolean remove(AuthRole role, AuthUser user, boolean flush = false) {
UserRole instance = UserRole.findByRoleAndUser(role, user)
instance ? instance.delete(flush: flush) : false
}
static void removeAll(AuthRole role) {
executeUpdate 'DELETE FROM UserRole WHERE role=:role', [role: role]
}
static void removeAll(AuthUser user) {
executeUpdate 'DELETE FROM UserRole WHERE user=:user', [user: user]
}
static mapping = {
id composite: ['user', 'role']
version false
}
}
他們是非常的插件創建它們的方式。
感謝, 人
出於某種原因(也許是我edieted它)我有錯誤的類在我的Config.groovy中。相反的: grails.plugins.springsecurity.authority.className = 'auth.AuthRole' 我: grails.plugins.springsecurity.authority.className = 'auth.AuthUser' 修復它後,我得到了以下例外: 2011-01-26 15:35:47,077 [http-9000-1] ERROR [/aquaWell].[default] - servlet默認的Servlet.service()引發異常 groovy.lang.MissingPropertyException:No這樣的屬性:啓用類:auth.AuthUser – 2011-01-26 14:55:16