【发布时间】:2012-04-10 00:35:07
【问题描述】:
我有三个域类User、Employee 和UserEmployee。
class User {
String username
//more atributes omitted
static hasMany = [ userEmployees : UserEmployee ]
static mapping = {
version false
table 'myUserTable'
id column: 'username', name: 'username'
}
}
class Employee {
long employeeCode
//more atributes omitted
static hasMany = [ userEmployees : UserEmployee ]
static mapping = {
id column: 'myColumn', name: 'employeeCode'
version false
table 'myViewHere'
}
}
class UserEmployee implements Serializable {
User user
Employee employee
static belongsTo = [ user : User, employee : Employee ]
static mapping = {
version false
table 'myRelationTable'
id composite: ['user','employee']
user(column: "username")
employee(column: "myColumn")
}
}
当我尝试查询某个用户可以访问的所有员工时,我收到 ORA-00904 错误:
println UserEmployee.withCriteria {
projections {
user {
eq('username', 'SOMEUSER')
}
}
}
休眠输出是这样的:
Hibernate: select * from ( select this_.username as usuario27_0_, from myUserTable this_ where this_.username=? ) where rownum <= ?
Hibernate: select this_.username as usuario24_0_, this_.code_employee as cod2_24_0_ from myRelationalTable this_ where (usu_alias1x1_.username=?)
为什么要创建别名usu_alias1x1_?
P.S.:我更改了域类名称和字段以便更好地理解。也许会是某个地方的错字。
编辑
我正在映射一个已经存在且无法将 PK 更改为 Grails 默认值的数据库。所以我使用id column 来声明密钥。
【问题讨论】:
标签: java oracle grails grails-orm ora-00904