Announcement Announcement Module
Collapse
No announcement yet.
how: many-to-many with between composite-id and id Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how: many-to-many with between composite-id and id

    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"
            >
    		
    		<key> 
    			<column name="idnumero" /> 
    			<column name="serie" />
    		</key> 
    		
                <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"
    		column=""
                    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
Working...
X