0

次のような 4 つのドメイン クラスがあるとします。

class Branch {
    String name
    static hasMany   = [users:Users] 
    static mappedBy  = [users:'branch']   
    static mapping = {                
        id          column: 'f_branch_id'
        name        column: 'f_name'
    }
}
class Users {
    String name
    static hasMany  = [account:Account]
    static mappedBy = [account:'user']
    static belongsTo= [branch:Branch, title:Title]
    static mapping = {
        id          column: 'f_user_id',
        name        column: 'f_name',   
        branch      column: 'k_branch_id'
    }
}
class Account {
    String username   
    static belongsTo   = [user:Users]   
    static mapping = {
        id              column: 'f_account_id'
        user            column: 'f_user_id'
        username        column: 'f_username'
    }
}
class JoinTable implements Serializable {
    Account account
    Role role    
    static mapping = {
        id              composite   : ['role', 'account']
        role            column      :'k_role_id'
        account         column      :'k_account_id'
        version false
    }    
}

基準クエリを使用して JoinTable からブランチを取得するにはどうすればよいですか? このプロセスを試してみましたが、エイリアスの問題で失敗しました

 def criteria = JoinTable.createCriteria()
     def list = criteria.list {             
         account {
                user{
                    branch{
                        eq("id", "2")
                    }
                }
         }
    }
4

1 に答える 1