-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Please help me map my Map relationship
PostPosted: Thu Sep 18, 2008 10:45 am 
Newbie

Joined: Tue Sep 16, 2008 3:52 pm
Posts: 4
Location: Austin
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


Top
 Profile  
 
 Post subject: Ok, here we go
PostPosted: Thu Sep 18, 2008 11:17 am 
Newbie

Joined: Tue Sep 16, 2008 3:52 pm
Posts: 4
Location: Austin
I think I found my own solution: I just stick in 4 "column" elements under the map-key-many-to-many. Not 100% sure this is right but at least I got it to export the schema:
Code:
  <map name="settings" table="config_settings">
    <key column="goldenConfigID" not-null="true" on-delete="cascade"/>
    <map-key-many-to-many class="EMS_Audit.audit.params.BasicAuditParameter">
      <column name="releaseName"/>
      <column name="nodeName"/>
      <column name="className"/>
      <column name="paramName"/>
    </map-key-many-to-many>
    <many-to-many class="EMS_Audit.audit.golden.GoldenParam"/>
  </map>


Hopefully that'll do the trick. Thanks for reading anyway!
Dan


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.