JPA实体在实施物料清单概念时出现错误 [英] JPA entity giving error on implementing Bill of material concept
问题描述
尝试使用JPA实体实施物料清单概念:-
IDE:Eclipse Helios;
罐子:eclipselink2.4.0,javax.persistence
实体如下:
Trying to implement the Bill of Material concept using JPA entity:-
IDE: Eclipse Helios;
Jars: eclipselink2.4.0 , javax.persistence
Entity is as follows:
@Id
@TableGenerator(name = "Config_Key_Incrementor", table = "id_generator", pkColumnName = "gen_name", valueColumnName = "gen_value", pkColumnValue = "conifg_id_gen", allocationSize = 1, initialValue = 1)
@GeneratedValue(strategy = TABLE, generator = "Config_Key_Incrementor")
@Column(name = "config_id")
private int configId;
@Column(name = "config_name")
private String configName;
//bi-directional many-to-one association to Bill_Of_Material
@ManyToOne
@PrimaryKeyJoinColumn(name="config_id")
private Configuration parent;
//bi-directional many-to-one association to Bill_Of_Material
@OneToMany(mappedBy="parent")
private List<Configuration> children = new ArrayList<Configuration>();
public Configuration getParent() {
return parent;
}
public void setParent(Configuration parent) {
this.parent = parent;
}
public List<Configuration> getChildren() {
return children;
}
public void setChildren(List<Configuration> children) {
this.children = children;
}
public int getConfigId() {
return configId;
}
public void setConfigId(int configId) {
this.configId = configId;
}
public String getConfigName() {
return configName;
}
public void setConfigName(String configName) {
this.configName = configName;
}
输出:
CREATE TABLE configuration
(
config_id integer NOT NULL,
config_name character varying(255),
CONSTRAINT configuration_pkey PRIMARY KEY (config_id ),
CONSTRAINT fk_configuration_config_id FOREIGN KEY (config_id)
REFERENCES configuration (config_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
错误: 该表已创建,但是缺少parent_config_id列,并且它与config_id的关系也丢失了.
Error: The table is getting created , but the column parent_config_id is missing and its relation to config_id is also missing.
推荐答案
您正在使用@PrimaryKeyJoinColumn(name ="config_id"),它指示主键还是所引用的Configuration父级的外键-因此它是它的自己的父母.您想使用@JoinColumn定义外键,或者将其保留为空白以使其使用默认值.
You are using @PrimaryKeyJoinColumn(name="config_id") which indicates that the primary key is also a foreign key to the referenced Configuration parent - so it is its own parent. You want to use @JoinColumn to define the foreign key, or leave it blank to have it use the default.
@ManyToOne
@JoinColumn(name="parent_config_id", referencedColumnName="config_id")
private Configuration parent;
这篇关于JPA实体在实施物料清单概念时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!