0
我想连接到遗留数据库。我的遗留数据库正在使用postgresql。我使用DB-逆向工程插件生成域类,生成的域类:Grails:连接到遗留数据库
class TableLogin {
String username
String password
Integer userLevel
static mapping = {
id name: "username", generator: "assigned"
version false
}
static constraints = {
username maxSize: 30
password nullable: true, maxSize: 36
userLevel nullable: true
}
}
我跑generate-all
,操作列表是做工精细。但是,当我点击一个数据/用户名(执行show动作),我得到这个错误:TableLogin不能与ID为空
发现我尝试使用此代码跟踪:
def rowLogin = TableLogin.get("supervisor")
log.error(rowLogin as JSON)
我得到了:
{"class":"webnico.TableLogin","id":null,"password":"2dcc509a6f7584","userLevel":0,"username":"supervisor"}
为什么id
为空? 我想是因为id为空,因此show动作不起作用
更新我的域类,成为:
class TableLogin {
String id
String username
String password
Integer userLevel
static mapping = {
id name: "username", generator: "assigned"
version false
}
static constraints = {
username maxSize: 30
password nullable: true, maxSize: 36
userLevel nullable: true
}
def afterLoad() {
id = username
}
}
的id
不再为空
{"class":"webnico.TableLogin","id":"supervisor","password":"2dcc509a6f7584","userLevel":0,"username":"supervisor"}
但是,演出动作仍然无效。展会网址似乎是正确的,http://mylocalhost.com:9000/webnico/tableLogin/show/supervisor但我仍然得到了同样的错误:TableLogin不能与ID为空发现
是不是就意味着当id
类型不是Long
我们不能使用支架(generate-all
)?