gpt4 book ai didi

java - 如何加入符合条件的实体?

转载 作者:行者123 更新时间:2023-11-30 03:32:18 24 4
gpt4 key购买 nike

我有两个实体类,它们的映射中不包含任何关联。

@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'

没有在映射中显式声明与 @OneToMany 注释的关联吗?

最佳答案

如果不映射两个实体对象,就不可能编写显式联接。但你可以做一个子查询。

Here is a reference to a similiar question.

And here the link to the answer containing a subquery example

关于java - 如何加入符合条件的实体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28743250/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com