【发布时间】:2013-08-20 20:58:36
【问题描述】:
select ptm.* from ProofTestMaster ptm LEFT JOIN
ProofTestApplicationMap ptam on ptm.proofTestID = ptam.proofTestID
LEFT JOIN ProofTestComapartmentMap ptcm on ptm.proofTestID = ptcm.proofTestID
where (ptam.applicationID = 3 and ptm.isDeleted = 0) or
(ptcm.compartmentID = 4 and ptm.isDeleted = 0)
其中ProofTestApplicationMap 和ProofTestComapartmentMap 是映射表,它们在java 端没有实体。
【问题讨论】:
-
希望这个链接能帮到你:) stackoverflow.com/questions/6165743/…
-
不,我需要使用标准 API 而不仅仅是 HQL 或 SQL。
-
很难映射 2 个关系和 3 个表。此外,维护这样的映射确实很复杂。如果您有一对多、多对多的关系,您还需要维护延迟加载策略,这会让您的工作更加努力。在我看来,这样的映射是不必要的。
-
使用 Criteria Object 的 createAlias 来定义连接
-
@erencan 那么您建议如何维护数据结构以使生活更轻松?
标签: java database hibernate hibernate-criteria