-->
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: how: many-to-many with between composite-id and id
PostPosted: Thu Feb 28, 2008 5:58 pm 
Newbie

Joined: Mon Mar 12, 2007 8:47 pm
Posts: 5
Hello guys

i need really your help

pls see this

Code:
public class CabeceraAlmacen implements Serializable{

   private static final long serialVersionUID = 1L;
   
   private AlmacenPK almacenPK;
   
   private String documento;
   private Date fecha;

   ...more fields

   /**
    * @hibernate.id generator-class="increment"
    * @NotasSuicidas even this not appear in the hbm.xml
    */
   public AlmacenPK getAlmacenPK() {
      return almacenPK;
   }

   public void setAlmacenPK(AlmacenPK almacenPK) {
      this.almacenPK = almacenPK;
   }


where

Code:
public class AlmacenPK implements Serializable{

   private static final long serialVersionUID = 1L;
   private String idnumero;
   private String serie;
   
   /**
    * @hibernate.property column="idnumero" length="6" not-null="true"
    */
   public String getIdnumero() {
      return idnumero;
   }
   public void setIdnumero(String idnumero) {
      this.idnumero = idnumero;
   }
   
   /**
    * @hibernate.property column="serie" length="3" not-null="true"
    */
   public String getSerie() {
      return serie;
   }
   public void setSerie(String serie) {
      this.serie = serie;
   }


so for CabeceraAlmacen its pk generated is is


Code:
<hibernate-mapping
>
    <class
        name="com.myapp.modelo.entidades.CabeceraAlmacen"
        table="cabeceraalmacen"
        discriminator-value="CABALM"
    >

        <composite-id
            name="almacenPK"
            class="com.myapp.modelo.entidades.AlmacenPK"
        >
                     <key-property
                        name="idnumero"
                        type="java.lang.String"
                        column="idnumero"
                        length="6"
                />

                     <key-property
                        name="serie"
                        type="java.lang.String"
                        column="serie"
                        length="3"
                />

        </composite-id>

....



now for this class

Code:
public class ArticuloNoAuto {

   private String idArticuloNoAuto;
   .. more fiedls
   
   /**
    * @hibernate.id column="idArticuloNoAuto" length="70" generator-class="assigned"
    */
   public String getIdArticuloNoAuto() {
      return idArticuloNoAuto;
   }
   public void setIdArticuloNoAuto(String idArticuloNoAuto) {
      this.idArticuloNoAuto = idArticuloNoAuto;
   }


so for ArticuloNoAuto its pk generated is is

Code:
<hibernate-mapping
>
    <class
        name="com.myapp.modelo.entidades.ArticuloNoAuto"
        table="articulonoauto"
    >

        <id
            name="idArticuloNoAuto"
            column="idArticuloNoAuto"
            type="java.lang.String"
            length="70"
        >
            <generator class="assigned">
              <!-- 
                  To add non XDoclet generator parameters, create a file named
                  hibernate-generator-params-ArticuloNoAuto.xml
                  containing the additional parameters and place it in your merge dir.
              -->
            </generator>
        </id>



so pls see that for one class the pk is composite-id and the other is id

i need really a relation many-to-many between these tables so

for the first class i can create without problems this

Code:
        <set
            name="articulosNoAuto"
            table="articulonoautocabeceraalmacen"
            lazy="true"
            cascade="none"
            sort="unsorted"
        >
      [b]
      <key>
         <column name="idnumero" />
         <column name="serie" />
      </key>
      [/b]
            <many-to-many
                class="com.myapp.modelo.entidades.ArticuloNoAuto"
                column="idArticuloNoAuto"
                outer-join="auto"
             />

        </set>


now the wonderful problem is for the other side

Code:
        <set
            name="cabecerasAlmacen"
            table="articulonoautocabeceraalmacen"
            lazy="true"
            inverse="true"
            cascade="none"
            sort="unsorted"
        >

            <key
                column="idArticuloNoAuto"
            >
            </key>

            <many-to-many
                class="com.myapp.modelo.entidades.CabeceraAlmacen"
      [b]column=""[/b]
                outer-join="auto"
             />
      
        </set>


how you can see column="" only accepts 1 field
instead for this case of 2 expected by
composite-id for CabeceraAlmacen

if i use
column="idnumero"

i recieve this error

Code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/xml/context/applicationContext-hibernate.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Foreign key (FK51ECAB101819CEDD:articulonoautocabeceraalmacen [idnumero])) must have same number of columns as the referenced primary key (cabeceraalmacen [idnumero,serie])
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)
   at java.security.AccessController.doPrivileged(Native Method)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)


even with column="idnumero,serie"

Code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/xml/context/applicationContext-hibernate.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Foreign key (FK51ECAB10406F666D:articulonoautocabeceraalmacen [idnumero,serie])) must have same number of columns as the referenced primary key (cabeceraalmacen [idnumero,serie])
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)
   at java.security.AccessController.doPrivileged(Native Method)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)


it seems the same error but

for the love of god,
how i can resolve this?

thanks so much in advanced


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 31, 2008 8:31 am 
Regular
Regular

Joined: Thu Mar 06, 2008 5:06 am
Posts: 68
use this:

Code:
<many-to-many
        class="com.myapp.modelo.entidades.CabeceraAlmacen"
        outer-join="auto"
>
    <column name="idnumero" />
    <column name="serie" />
</many-to-many>


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.