Hibernate Criteria API 多重连接
我的休眠实体如下:
@Entity
@Table(name = "EditLocks")
public class EditLock extends AuditableEntity {
/** The document that is checked out. */
@OneToOne
@JoinColumn(name = "documentId", nullable = false)
private Document document;
文档看起来像这样:
public class Document extends AuditableEntity {
/** Type of the document. */
@ManyToOne
@JoinColumn(name = "documentTypeId", nullable = false)
private DocumentType documentType;
本质上我想编写的查询是:
Select * from EditLocks el, Document docs, DocumentTypes dt where el.documentId = docs.id and docs.documentTypeId = dt.id and dt.id = 'xysz';
如何使用休眠条件 api 执行此操作?
My hibernate entities are as follows:
@Entity
@Table(name = "EditLocks")
public class EditLock extends AuditableEntity {
/** The document that is checked out. */
@OneToOne
@JoinColumn(name = "documentId", nullable = false)
private Document document;
Document then looks like this:
public class Document extends AuditableEntity {
/** Type of the document. */
@ManyToOne
@JoinColumn(name = "documentTypeId", nullable = false)
private DocumentType documentType;
Essentially the query I want to write is:
Select * from EditLocks el, Document docs, DocumentTypes dt where el.documentId = docs.id and docs.documentTypeId = dt.id and dt.id = 'xysz';
How do I do this with the hibernate criteria api?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该可以做到:
您需要添加别名才能到达具有要查询的属性的对象。
That should do it:
You need to add aliases to reach the object having the property on which you want to query.
所以看起来您只是想获取具有 DocumentType id = 'xyz' 的文档的 EditLock。我假设 Document 和 DocumentType 具有标准的 Hibernate 映射:我认为
Hibernate 应该能够为您找出连接。
So it looks like you are just trying to get the EditLocks who have Documents with a DocumentType id = 'xyz'. I'm assuming that Document and DocumentType have standard Hibernate mappings:
Hibernate should be able to figure out the joins for you I think.