我对hibernate注释有一些问题。我在这里有一些方案:
feature_map
module_name
(PK)(FK m_module_fk
)feature_code
(PK)(FK m_feature_fk
)module_name
(PK)feature_code
(PK)我从hibernate和其他网站尝试了几种方法,但它没有用。 谁可以帮我这个?
对不起,我没有告诉你所有的代码。我的意思是,我请求您帮助自己的代码将其生成为hibernate注释代码。对不起,这是我的错误。我有正确的,我昨晚发现了。 CMIIW。
以下是我的代码:
FeatureMap.class
@Entity
@Table(name = "M_FEATURE_MAP")
@IdClass(FeatureMapPk.class)
public class FeatureMap implements Serializable {
@Id
@Column(name = "module_name")
private String moduleName;
@Id
@Column(name = "feature_code")
private String featureCode;
@MapsId("moduleName")
@OneToOne
@JoinColumn(name = "module_name", referencedColumnName = "module_name",
insertable = false, updatable = false)
private Module module;
@MapsId("featureCode")
@OneToOne
@JoinColumn(name = "feature_code", referencedColumnName = "feature_code",
insertable = false, updatable = false)
private Feature feature;
/*Getter Setter, hash equals and toString*/
}
FeatureMapPk.class
public class FeatureMapPk implements Serializable {
private String moduleName;
private String featureCode;
public FeatureMapPk(){
}
public FeatureMapPk(String moduleName, String featureCode){
this.moduleName = moduleName;
this.featureCode = featureCode;
}
/*Getter Setter, hash equals and toString*/
}
Module.class
@Entity
@Table(name = "M_MODULE")
public class Module implements Serializable {
@Id
@Column(name = "module_name")
private String moduleName;
@JsonIgnore
@OneToOne(fetch = FetchType.LAZY, mappedBy = "module")
private FeatureMap featureMap;
/*Getter Setter, hash equals and toString*/
}
Feature.class
@Entity
@Table(name = "M_FEATURE")
public class Feature implements Serializable {
@Id
@Column(name = "feature_code")
private String featureCode;
@JsonIgnore
@OneToOne(fetch = FetchType.LAZY, mappedBy = "feature")
private FeatureMap featureMap;
/*Getter Setter, hash equals and toString*/
}
非常感谢回答:) 在我犯错误之前,我很抱歉。
答案 0 :(得分:0)
如果没有看到您的代码,您尝试过的几种方式以及实际架构不仅仅是主键,我们如何才能真正提供帮助。
尽管如此,您很可能对复合键不感兴趣,但对模块和要素中的简单OneToMany或ManyToMany映射以及FeatureMap没有实体感兴趣。