我有两个实体类,它们的映射中不包含任何关联。
@Entity
@Table(schema = "mailing", name = "recipient_code_statistics")
public class RecipientCodeStatistics {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;
@Column(name = "recipient_code_id", unique = true)
private long recipientCodeId;
//GET, SET
}
和
@Entity
@Table(schema = "mailing", name = "recipient_code")
public class RecipientCode {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private long id;
@Column(name = "code")
private String code;
//GET ,SET
}
是否可以编写criteria
查询,类似于以下内容:
SELECT *
FROM recipient_code_statistic
LEFT OUTER JOIN recipient_code
ON recipient_code_statistic.recipient_code_id = recipient_code.id
WHERE recipient_code.code = '123'
Whitout在映射中明确声明与@OneToMany
注释的关联吗?
答案 0 :(得分:1)
在不映射两个实体对象的情况下编写显式连接是不可能的。但你可以做一个子查询。
Here is a reference to a similiar question.
And here the link to the answer containing a subquery example
答案 1 :(得分:1)
尝试使用本机查询@NativeQuery()