Hibernate标准 - 连接多个表并形成用户对象

时间:2016-05-31 17:03:06

标签: java hibernate criteria hibernate-mapping hibernate-criteria

我正在尝试连接多个表并将表列映射到用户对象列表。

下面是SQL查询,我试图使用Hibernate Criteria转换为ORM:

SELECT table1.domainname, table2.policyname,table3.filterpath,table4.userdirectoryname
FROM table1, table2,table3, table4 
WHERE table3.domainoid = table1.domainoid
AND table3.policyoid = table2.policyoid
AND table3.userdirectoryoid = table4.userdirectoryoid  
AND table1.domainname = 'admin'

从上面的查询中,我们将获得用户对象列表并尝试将结果映射到用户对象。下面是要形成的用户对象的POJO类。

public class DomainDetails {
    String domainName, policyName, filterPath, userDirName;

    public DomainDetails(String domainName, String policyName, String filterPath, String userDirName) {
        super();
        this.domainName = domainName;
        this.policyName = policyName;
        this.filterPath = filterPath;
        this.userDirName = userDirName;
    }

    // getters and setters...
}

如何连接多个表以及将各列映射到用户对象?

感谢帮助......谢谢

1 个答案:

答案 0 :(得分:0)

您可以使用映射注释 .. Mapping entity associations/relationships