本文介绍了Hibernate嵌套属性别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个班: @Entity
@Table(name =TOPUP_MESSAGE)
公共课ReportFee {
// ... ID&其他属性
@ManyToOne
@JoinColumn(name =CONTRACT_ID)
私有ContractDetail contractDetail;
// GETTERS AND SETTERS
}
和ContractDetail类是这样的:
@Entity
@Table(name =CONTRACT_DETAIL)
公共类ContractDetail {
// ... ID&其他属性
@ManyToOne
@JoinColumn(name =CONTRACT_ID)
私人合同;
// GETTERS AND SETTERS
}
我的合约类是这样的:
@Entity
@Table(name =CONTRACT)
public class Contract implements {
// ... ID&其他属性
@ManyToOne
@JoinColumn(name =OPERATOR_ID)
私人操作员操作员;
// GETTERS AND SETTERS
}
我定义了像这样的别名,但这是错误的:
Session session =(Session)this.em.getDelegate();
Criteria crit = session.createCriteria(getEntityClass());
crit = crit.createAlias(contractDetail,cd,JoinType.LEFT_OUTER_JOIN);
crit = crit.createAlias(contract,c,JoinType.LEFT_OUTER_JOIN);
crit = crit.createAlias(operator,op,JoinType.LEFT_OUTER_JOIN);
标准c = Restrictions.eq(cd.cd.op,运算符);
crit.add(c);
列表结果= crit.list();
但不幸的是我得到这个错误:
这里是类的创建方式:
---- ReportFee(私人ContractDetail contractDetail)
|
------ ContractDetail(私人合约合约)
|
--------合约(私人合约合约)
我怎么解决这个问题,thanx提前???我解决了这个问题,当我定义了嵌套的层次结构时,我解决了这个问题。
像这样: Session session =(Session)this.em.getDelegate();
Criteria crit = session.createCriteria(getEntityClass());
crit = crit.createAlias(contractDetail,cd,JoinType.LEFT_OUTER_JOIN);
crit = crit.createAlias(cd.contract,c,JoinType.LEFT_OUTER_JOIN);
标准标准= Restrictions.eq(c.operator,operator);
crit.add(c);
列表结果= crit.list();
I have this class:
@Entity
@Table(name = "TOPUP_MESSAGE")
public class ReportFee {
//... ID & Other Properties
@ManyToOne
@JoinColumn(name="CONTRACT_ID")
private ContractDetail contractDetail;
//GETTERS AND SETTERS
}
and ContractDetail class is like this:
@Entity
@Table(name = "CONTRACT_DETAIL")
public class ContractDetail {
//... ID & Other Properties
@ManyToOne
@JoinColumn(name = "CONTRACT_ID")
private Contract contract;
//GETTERS AND SETTERS
}
My Contract class is like this:
@Entity
@Table(name = "CONTRACT")
public class Contract implements {
//... ID & Other Properties
@ManyToOne
@JoinColumn(name = "OPERATOR_ID")
private Operator operator;
//GETTERS AND SETTERS
}
I defined my alias like this but It's wrong :
Session session = (Session)this.em.getDelegate();
Criteria crit = session.createCriteria(getEntityClass());
crit = crit.createAlias("contractDetail", "cd", JoinType.LEFT_OUTER_JOIN);
crit = crit.createAlias("contract", "c", JoinType.LEFT_OUTER_JOIN);
crit = crit.createAlias("operator", "op", JoinType.LEFT_OUTER_JOIN);
Criterion c= Restrictions.eq("cd.cd.op", operator);
crit.add(c);
List result = crit.list();
but unfortunately I get this error:
here is how the classes has been created :
----ReportFee (private ContractDetail contractDetail)
|
------ ContractDetail (private Contract contract)
|
-------- Contract (private Contract contract)
how Am I going to solve this, thanx in advance ???
解决方案
I solved this problem when I defined the nested hierarchy like this:
Session session = (Session)this.em.getDelegate();
Criteria crit = session.createCriteria(getEntityClass());
crit = crit.createAlias("contractDetail", "cd", JoinType.LEFT_OUTER_JOIN);
crit = crit.createAlias("cd.contract", "c", JoinType.LEFT_OUTER_JOIN);
Criterion criterion= Restrictions.eq("c.operator", operator);
crit.add(c);
List result = crit.list();
这篇关于Hibernate嵌套属性别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!