Hibernate RIGHT JOIN结果未正确映射

时间:2016-06-14 12:17:22

标签: java spring hibernate

我有一个数据源和ds_restriction表。我想选择所有数据源,无论它们是否受限于休眠状态。这是映射的类:

@Entity
@Table(name="datasource")
public class DatasourceDom implements Serializable {

@Id
@Column(name = "id")    
private int id;

@Column(name = "alias")
private String alias;   

@Column(name = "url")
private String url;


@Entity
@Table(name = "ds_restriction")
public class DsRestrictionDom implements Serializable { 

@Id
@Column(name = "datasource_id")
private int datasourceId;

@Id
@Column(name = "principal")
private String principal;   

@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "datasource_id")
@ElementCollection(targetClass = DatasourceDom.class)
private DatasourceDom datasource;

这是获取数据源的代码:

public List<DatasourceRestrictionDom> getDatasorcesRestictions() {
    Session session = getCurrentSession();
    Criteria criteria = session.createCriteria(DsRestrictionDom.class);
    criteria.createCriteria("datasource","ds",JoinType.RIGHT_OUTER_JOIN);
    List<DatasourceRestrictionDom> dsList = criteria.list();        
    return dsList;
}

当我得到结果时,没有限制的数据源返回null。 映射中的错误是什么?

0 个答案:

没有答案