嵌套一对多中的外键关系

时间:2015-06-04 00:54:57

标签: java hibernate foreign-keys hibernate-mapping

我有这些类,具有单向一对多关系映射,如下所示:

@Entity
public class DatabaseDetailsVO {
    @Id
    // primary key for DatabaseDetailsVO
    private String databaseName;

    @OneToMany
    private List<TableDetailsVO>;
}

@Entity
public class TableDetailsVO {
    @Id
    // primary key of TableDetailsVO must be database name 
    // and tableName with databaseName as foriegn key from DatabaseDetailsVO
    private String tableName;

    @OneToMany
    private List<ColumnDetailsVO>;
}

public class ColumnDetailsVO {
    @Id
    // primary key of ColumnDetailsVO must be columnName with
    // databaseName and tableName as foriegn key from TableDetailsVO
    private String columnName;

    private String columnDataType;
    ...
}

如何使用Hibernate注释解决这个问题?我正在使用Hibernate 3.3.1版本。

1 个答案:

答案 0 :(得分:-1)

@OneToMany(fetch = FetchType.LAZY, mappedBy = "DatabaseDetailsVO")
public Set<TableDetailsVO> getTableDetailsVOs() {
    return this.stockTableDetailsVOs;
}

此链接可以为您提供帮助 - mkyong