Hi.
I'm trying to map a ternary relationship that I've represented in Java as a Map. GoldenConfig is the class(entity) that contains a map of BasicAuditParameter to GoldenParam.
GoldenConfig and GoldenParam have simple integer identifiers but BasicAuditParameter is a legacy entity that requires a composite identifier of four strings.
Here's the interesting parts of the GoldenParam.hbm.xml and BasicAuditParameter.hbm.xml:
Code:
<class name="GoldenParam">
<id name="paramID">
<generator class="native"/>
</id>
</class>
<class name="BasicAuditParameter"
table="audit_parameters"
mutable="false"
schema="necb_user">
<composite-id name="nodeID"
class="BasicAuditParameter$ID">
<key-property name="releaseName" column="logicalVerStr"/>
<key-property name="nodeName" column="node"/>
<key-property name="className" column="auditClass"/>
<key-property name="paramName" column="name"/>
</composite-id>
</class>
Clear so far? I hope so. Now, in GoldenConfig, I've got a Map<BasicAuditParameter, GoldenParam>.
My question is, what do I put in GoldenConfig.hbm.xml to properly map the relationship?
So far I've figured out:
Code:
<class name="GoldenConfig">
<id name="goldenConfigID">
<generator class="native"/>
</id>
<map name="settings" table="config_settings">
<key column="goldenConfigID" not-null="true" on-delete="cascade"/>
<map-key-many-to-many class="BasicAuditParameter"/>
<many-to-many class="GoldenParam"/>
</map>
</class>
Obviously that's wrong because, when I try to parse it to generate the DDL, I get:
Code:
[hibernatetool] org.hibernate.MappingException: Foreign key (FKF25AF4805987A3EB:config_settings [idx
])) must have same number of columns as the referenced primary key (audit_parameters [logicalVerStr,
node,auditClass,name])
So can you please tell me what I'm missing, what I need to change to make this work?
Thanks in advance,
Dan
PS If it helps, I'm using hibernate 3.3; here's the interesting parts of the Java source:
Code:
public class GoldenConfig implements java.io.Serializable {
private int goldenConfigID;
//Here's the map:
private Map<BasicAuditParameter, GoldenParam> settings;
public GoldenConfig() {
settings = new HashMap<BasicAuditParameter, GoldenParam>();
} //Ends constructor GoldenConfig
public int getGoldenConfigID() {
return goldenConfigID;
} //Ends method getGoldenConfigID
private void setGoldenConfigID(int goldenConfigID) {
this.goldenConfigID = goldenConfigID;
} //Ends method setGoldenConfigID
public Map<BasicAuditParameter, GoldenParam> getSettings() {
return settings;
} //Ends method getSettings
public void setSettings(Map<BasicAuditParameter, GoldenParam> settings) {
this.settings = settings;
} //Ends method setSettings
} //Ends class GoldenConfig
public class GoldenParam implements java.io.Serializable {
//It's a one-way relationship, so no references to GoldenConfig here
private Integer paramID;
public GoldenParam() {
} //Ends constructor GoldenParam
@Id @GeneratedValue
public Integer getParamID() {
return paramID;
} //Ends method getParamID
private void setParamID(Integer paramID) {
this.paramID = paramID;
} //Ends method setParamID
} //Ends class GoldenParam
public class BasicAuditParameter implements java.io.Serializable {
public static class ID extends AuditClass.ID
implements java.io.Serializable {
private String name;
private ID() {
super();
} //Ends constructor ID
private void setParamName(String name) { this.name = name; }
public String getParamName() { return name; }
public int hashCode() {
return super.hashCode() ^ name.hashCode();
} //Ends method hashCode
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof ID)) return false;
ID id = (ID)o;
return super.equals(id) && id.name.equals(name);
} //Ends method equals
} //Ends class ID
protected ID id;
protected BasicAuditParameter() {
id = new ID();
} //Ends constructor
public ID getNodeID() {
return id;
} //Ends method getNodeID
private void setNodeID(ID nodeID) {
id = nodeID;
} //Ends method setNodeID
private void setReleaseName(String release) {
id.setReleaseName(release);
} //Ends method setREleaseName
public String getReleaseName() {
return id.getReleaseName();
} //Ends method getReleaseName
void setNodeName(String node) {
id.setNodeName(node);
} //Ends method setNodeName
public String getNodeName() {
return id.getNodeName();
} //Ends method getNodeName
public String getNode() {
return getNodeName();
} //Ends method getNode
public String getClassName() {
return id.getClassName();
} //Ends method getClassName
public String getAuditClass() {
return getClassName();
} //Ends method getAuditClass
public void setClassName(String auditClass) {
id.setClassName(auditClass);
} //Ends method setClassName
public String getParamName() {
return id.getParamName();
} //Ends method getParamName
void setParamName(String name) {
id.setParamName(name);
} //Ends method setParamName
} //Ends class BasicAuditParameter