-->
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.  [ 5 posts ] 
Author Message
 Post subject: Many-to-one with multiple columns
PostPosted: Thu May 18, 2006 2:04 pm 
Newbie

Joined: Thu May 18, 2006 1:46 pm
Posts: 10
Hello there! I have a many to one relationship where the end association has a composite key. The problem is that one of the keys are also being used by my many side class:
Code:
<composite-id
            name="pk"
            class="PK"
        >
                     <key-property
                        name="codigoReceita"
                        type="CodigoReceitaEnum"
                        column="CODREC"
                />

                     <key-property
                        name="cidade"
                        type="java.lang.Integer"
                        column="CODCID"
                />

                     <key-property
                        name="contrato"
                        type="java.lang.Integer"
                        column="CONTRA"
                />

                     <key-property
                        name="ponto"
                        type="java.lang.Integer"
                        column="PONTO"
                />

        </composite-id>

        <many-to-one
            name="pacote"
            class="Pacote"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
        >
           <column name="CODCID" ></column>
           <column name="CODPROG"></column>
        </many-to-one>


Well, Hibernate complains about CODCID being used twice. I've already mapped a column twice and then used the update/insert = false. Problem is I can't add these properties to my many-to-one columns.

How can I solve this?

Regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 18, 2006 2:18 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
You have true instead of false for insert and update on <many-to-one>

Code:
<many-to-one  name="pacote"
            class="Pacote"
            cascade="none"
            outer-join="auto"
            update="false"
            insert="false"
        >
           <column name="CODCID" ></column>
           <column name="CODPROG"></column>
</many-to-one>


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 10:08 pm 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Hi vinicius.carvalho

May I know how's your coding for the class "PK"?

I'm working on composite and came across your posting, hope you can give me some advice on how's the coding for that class.

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 24, 2006 10:46 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
His class would be as follows

Code:
public class PK implements Serializable {
   private CodigoReceitaEnum codigoReceita;
   private Integer cidade;
   private Integer contrato;
   private Integer ponto;

   // PersistentPojo is mapping class for
   // which this compositePK applies
   public boolean equals( PersistentPojo second ){
      // this removes warning message
      // use EqualsBuilder from commons-lang
   }

   public int hashCode(){
      // use HashCodeBuilder
      // from commons-lang
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 12:30 am 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
thanks.

I found the example on composite id already from the hibernate installation folders.

Eg.
....\hibernate-3.1\test\org\hibernate\test\cid


Btw, does anyone know how to specify the xdoclet tag for the case of @hibernate.composite-id in Java classes comment area (netbeans environment)?

reason being it seems like xdoclet complains during build time if there's not @hibernate.id found.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.