と の 3 つのドメイン クラス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_
が作成される理由
PS: ドメイン クラスの名前とフィールドを変更して、理解を深めました。多分どこかでタイプミスでしょう。
編集
既に存在するデータベースをマッピングしていますが、PK を Grails のデフォルトに変更することはできません。だから私はid column
キーを宣言するために使用しています。