我的目标是准备。基于params,我想从另一个表中添加数据-如果为true,则包含,如果不是,则不包含。为此,我假设需要创建join并创建规范。但我做这件事有困难。ex请求:
ai?first=true
第一实体:
@Entity
@Table(name = "ai_first")
public class First {
@EmbeddedId
private FirstId firstId;
可嵌入:
@Embeddable
public class FirstId implements Serializable {
@Column(name = "second_id")
private Long secondtId;
@Column(name = "create_time")
private Long secondCreateTimeInSeconds;
第二实体:
@Entity
@Table(name="ai_second")
public class Second implements Serializable
{
@Id
@Column(name="ai_second_id", updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name="create_time")
private Long createTimeInSeconds;
@OneToMany
private List<First> first;
规范:
public Specification<Second> includeFirst() {
return (Specification<Second>) (second, query, cb) -> {
Join<Second, First> firstJoin = second.join("first");
return cb.and(
cb.equal(firstJoin.get("firstId").get("secondId"), second.get("id")),
cb.equal(firstJoin.get("firstId").get("secondCreateTimeInSeconds"), second.get("createTimeInSeconds"))
);
};
}
我的错误:表'ai.ai\u second\u first'不存在。
我做错了什么?也许有更好的方法?
暂无答案!
目前还没有任何答案,快来回答吧!