就我而言,我有一个 SQL 查询,如下所示:
select * from event_instance where (object_id, object_type) in
(<LIST OF TUPLES RETRIEVED FROM SUBQUERY>);
我想在 Hibernate Entities 上映射它,但这个查询有问题。我的映射如下所示:
@Entity
@Table(name="event_instance")
public class AuditEvent {
<OTHER_FIELDS>
@Column( name = "object_type", nullable = false)
private String objectType;
@Column( name ="object_id" , nullable = false)
private Integer objectId;
}
第二个实体:
@Entity
@Table(schema = "els" ,name = "acg_objects")
public class AcgObject implements Serializable{
@Id
@Column(name = "acg_id")
private String acgId;
@Id
@Column(name="object_type")
private String objectType;
@Id
@Column(name="object_id")
private Integer objectId;
<OTHER FIELDS>
}
我已经运行了获取 AcgObjects 的查询,对于我的 DAO,我得到 List 唯一我想做的就是使用以下条件查询一个 touple:
crit.add(Restrictions.in("objectType,objectId",<List of tuples>);
可能吗?我试图使用@Embedded 对象,但不知道如何为它构建查询。请帮忙