我有两个简单的实体问题和标签,以及它们之间的many-to-many
关系。一切正常,除非我想删除导致此异常的问题:Ebean.delete(Issue.class, id)
javax.persistence.PersistenceException: Query threw SQLException:Unknown column
'issue_id' in 'where clause'
Bind values:[1b7e5955c26b51dex546fca27x13cc54c2531x-7fef, ]
Query was:
select t0.id c0
from tag t0
where issue_id=?
非常奇怪的是,生成的 SQL 显然是错误的。它尝试访问表issue_id
中的antag
但没有。我希望这不是 Ebean 中的错误,而只是我的一个错误,但我不知道它可能是什么。
这是实体 bean(我删除了 getter/setter)和 Ebean 生成的 DDL:
发行实体
@Entity
public class Issue {
@Id @Column(length=64)
private String id; // <-- I use assigned ids
@Version
private Date timeStamp;
private String title;
private String description;
private String createdBy;
@CreatedTimestamp
private Date createdAt;
private String state;
@ManyToMany(cascade=CascadeType.ALL)
@JoinTable(
name="issue_tag",
joinColumns={@JoinColumn(name="issue_id", referencedColumnName="id")},
inverseJoinColumns={@JoinColumn(name="tag_id", referencedColumnName="id")})
private Set<Tag> tags;
}
标记实体
@Entity
public class Tag {
@Id @Column(length=64)
private String id; // <-- I use assigned ids
@Version
private Date timeStamp;
private String name;
@ManyToMany(mappedBy="tags", cascade=CascadeType.ALL)
private Set<Issue> issues;
}
生成的 DDL
create table issue (
id varchar(64) not null,
title varchar(255),
description varchar(255),
created_by varchar(255),
state varchar(255),
time_stamp datetime not null,
created_at datetime not null,
constraint pk_issue primary key (id))
;
create table tag (
id varchar(64) not null,
name varchar(255),
time_stamp datetime not null,
constraint pk_tag primary key (id))
;
create table issue_tag (
issue_id varchar(64) not null,
tag_id varchar(64) not null,
constraint pk_issue_tag primary key (issue_id, tag_id))
;
alter table issue_tag add constraint fk_issue_tag_issue_01 foreign key (issue_id) references issue (id) on delete restrict on update restrict;
alter table issue_tag add constraint fk_issue_tag_tag_02 foreign key (tag_id) references tag (id) on delete restrict on update restrict;