Hibernate 标准、连接或
我正在尝试使用连接表、使用 Restrictions.or 和 Restrictions.ilike 来完成临时查询
我的实体看起来像:
@Entity
@Table(name="CASE_REVIEW")
public class CaseReview {
@Id
@Column(name = "REVIEW_ID", unique = true, nullable = false, length = 19)
private Long reviewId;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "CASE_ID", nullable = false)
private Case reviewCase;
}
@Entity
@Table(name = "CASE")
public class Case {
@Id
@Column(name = "ID", unique = true, nullable = false, length = 19)
private Long id;
@OneToOne( fetch=FetchType.EAGER )
@JoinColumn( name="STUDENT_ID" , referencedColumnName="ID",
private StudentInformation studentInformation;
}
@Entity
@Table( name="STUDENT")
public class StudentInformation {
@Id
@Column( name="ID")
private Long id;
@Column( name="LAST_NAME")
private String lastName;
@Column( name="FIRST_NAME")
private String firstName;
}
我的代码执行如下操作:
Criteria c = session.createCriteria( CaseReview.class );
c.createAlias( "reviewCase" , "reviewCase");
c.createAlias( "reviewCase.studentInformation" , "reviewCasestudentInformation");
c.add( Restrictions.or( Restrictions.ilike("reviewCasestudentInformation.lastName" , "%e%" ), Restrictions.ilike( "reviewCasestudentInformation.firstName" , "%e" )));
我收到 org.hibernate.QueryException: 无法解析属性:回顾案例学生信息:案例回顾。我还尝试创建多层别名:
c.createAlias( "reviewCase.studentInformation" , "reviewCaseStudentInformation");
并在restriction.or 中使用它,得到相同的结果。奇怪的是,任何一组别名都可以在
Order.asc( "reviewCaseStudentInformation.lastName")
几乎不知所措的情况下正常工作。建议?
I'm trying to accomplish ad-hoc queries using joined tables, using an Restrictions.or and Restrictions.ilike
My entities look like:
@Entity
@Table(name="CASE_REVIEW")
public class CaseReview {
@Id
@Column(name = "REVIEW_ID", unique = true, nullable = false, length = 19)
private Long reviewId;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "CASE_ID", nullable = false)
private Case reviewCase;
}
@Entity
@Table(name = "CASE")
public class Case {
@Id
@Column(name = "ID", unique = true, nullable = false, length = 19)
private Long id;
@OneToOne( fetch=FetchType.EAGER )
@JoinColumn( name="STUDENT_ID" , referencedColumnName="ID",
private StudentInformation studentInformation;
}
@Entity
@Table( name="STUDENT")
public class StudentInformation {
@Id
@Column( name="ID")
private Long id;
@Column( name="LAST_NAME")
private String lastName;
@Column( name="FIRST_NAME")
private String firstName;
}
My code does something like the following:
Criteria c = session.createCriteria( CaseReview.class );
c.createAlias( "reviewCase" , "reviewCase");
c.createAlias( "reviewCase.studentInformation" , "reviewCasestudentInformation");
c.add( Restrictions.or( Restrictions.ilike("reviewCasestudentInformation.lastName" , "%e%" ), Restrictions.ilike( "reviewCasestudentInformation.firstName" , "%e" )));
I'm getting org.hibernate.QueryException: could not resolve property: reviewCasestudentInformation of: CaseReview. I've also tried creating multi-tier aliases:
c.createAlias( "reviewCase.studentInformation" , "reviewCaseStudentInformation");
and using that in the restriction.or with the same results. Strangely enough either set of aliases work fine for
Order.asc( "reviewCaseStudentInformation.lastName")
Pretty much at a loss. Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建另一个标准 - 即子标准 - 像这样:
PS。我认为
ReviewCase
是CaseReview
上的一个字段并没有帮助......它使代码相当混乱!You need to create another criteria — ie a subcriteria — like this:
PS. I reckon it doesn't help that
ReviewCase
is a field onCaseReview
... it makes the code rather confusing!