在我们目前的项目中,我们遇到了一些困难。我最近更改了一些Hibernate Beans(我们的文章Bean和一些底层的东西),我运行了一些测试,一切看起来都很好。现在我的队友对此消息有例外:
Foreign key (FK_09fd525ae6654c059394d22cc15:ARTBILDER [artikel_fk,servdat_fk])) must have same number of columns as the referenced primary key (ARTIKEL [AUTOIN_FIX])
注释肯定是正确的。我有同样的问题,并决定从头开始在我的计算机上设置项目,问题就消失了。这些问题可能是什么原因?
我们正在研究遗留数据库,并且只将我们的对象映射到数据库,而不是使用hibernate生成数据库。我们正在使用HibernateSearch进行全文搜索(可能这是相关的,因为这是在我添加HibernateSearch Annotations之后第一次出现这种情况)。
我们正在使用Firebird 2.5实例。
编辑:
这是错误来自的属性:
ID类:
@Embeddable
public class ID implements Serializable {
private static final long serialVersionUID = 1810044174631580834L;
private Long autoin;
private Integer serverId;
public ID() {
}
public ID(Long autoin, Integer serverId) {
this.autoin = autoin;
this.serverId = serverId;
}
@Column(name = "autoin_fix")
public Long getAutoin() {
return this.autoin;
}
@Column(name = "servdat_fk")
public Integer getServerId() {
return this.serverId;
}
public void setAutoin(Long autoin) {
this.autoin = autoin;
}
public void setServerId(Integer serverId) {
this.serverId = serverId;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((this.autoin == null) ? 0 : this.autoin.hashCode());
result = prime * result
+ ((this.serverId == null) ? 0 : this.serverId.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (this.getClass() != obj.getClass()) {
return false;
}
ID other = (ID) obj;
if (this.autoin == null) {
if (other.autoin != null) {
return false;
}
} else if (!this.autoin.equals(other.autoin)) {
return false;
}
if (this.serverId == null) {
if (other.serverId != null) {
return false;
}
} else if (!this.serverId.equals(other.serverId)) {
return false;
}
return true;
}
@Override
public String toString() {
return new StringBuilder().append("ID [").append(this.autoin)
.append("_").append(this.serverId).append("]").toString();
}
}
文章类:
@Indexed
@Entity
@Table(name = "ARTIKEL")
public class Article {
private ID id;
private List<Picture> pictures;
...
@DocumentId
@EmbeddedId
@FieldBridge(impl = IDBridge.class)
public ID getId() {
return id;
}
@OneToMany
@JoinColumns({
@JoinColumn(name = "artikel_fk", referencedColumnName = "autoin_fix"),
@JoinColumn(name = "servdat_fk", referencedColumnName = "servdat_fk") })
@IndexedEmbedded
public List<Picture> getPictures() {
return pictures;
}
}
图片类:
@Entity
@Table(name = "ARTBILDER")
public class Picture extends BasePicture {
...
protected ID id;
@EmbeddedId
@FieldBridge(impl = IDBridge.class)
@Field(store = Store.YES, index = Index.YES)
public ID getId() {
return id;
}
...
}
EDIT2:我可能知道这些来自何处,请待命。
EDIT3:不,不是错误。
EDIT4:这是DDL:
CREATE TABLE ARTIKEL
(
AUTOIN_FIX NUM10_0 DEFAULT 0,
SERVDAT_FK NUM10_0 DEFAULT 0,
...
PRIMARY KEY (AUTOIN_FIX,SERVDAT_FK)
);
CREATE TABLE ARTBILDER
(
AUTOIN_FIX NUM10_0 DEFAULT 0,
ARTIKEL_FK NUM10_0 DEFAULT 0,
SERVDAT_FK NUM10_0 DEFAULT 0,
...
PRIMARY KEY (AUTOIN_FIX,SERVDAT_FK)
);
答案 0 :(得分:0)
这是完整的link and description
OneToMany(fetch = FetchType.LAZY)
@JoinTable(name = "DATA_VALUE", joinColumns = {
@JoinColumn(name = "DATA_ID"),
}, inverseJoinColumns = {
@JoinColumn(name = "COLUMN_NM")
})
List<DataValue> dataValueList;
或更多描述性
@Entity
public class Parent implements Serializable {
@Id
public ParentPk id;
public int age;
@OneToMany(cascade=CascadeType.ALL)
@JoinColumns ({
@JoinColumn(name="parentCivility", referencedColumnName = "isMale"),
@JoinColumn(name="parentLastName", referencedColumnName = "lastName"),
@JoinColumn(name="parentFirstName", referencedColumnName = "firstName")
})
public Set<Child> children; //unidirectional
...
}