-->
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.  [ 8 posts ] 
Author Message
 Post subject: composite-id with fk as pk
PostPosted: Tue Aug 17, 2004 4:55 pm 
Newbie

Joined: Fri Dec 19, 2003 1:31 pm
Posts: 12
Hibernate version: 2.1.4

Mapping documents:
Sector
<hibernate-mapping package="server.domain">
<class name="Sdec_sectorInfo" table="SDEC_SECTOR">
<id column="COD_SECTOR"
name="codSector"
type="integer">
<generator class="native" />
</id>
....

Prestamo
<hibernate-mapping package="server.domain">
<class name="Sdem_prestamoInfo" table="SDEM_PRESTAMO">
<composite-id class="Sdem_prestamoPK" name="id">
<key-property column="COD_HISTORICO"
name="codHistorico"
type="integer" />
<key-many-to-one class="Sdec_sectorInfo"
column="COD_SECTOR"
name="codSector" />
<key-property column="COD_PRESTAMO"
name="codPrestamo"
type="string" />
</composite-id>
....

Amortizacion
<hibernate-mapping package="server.domain">
<class name="Sdem_amortizacionInfo" table="SDEM_AMORTIZACION">
<composite-id class="Sdem_amortizacionPK" name="id">
<key-many-to-one class="Sdem_prestamoPK" name="id">
<column name="COD_SECTOR" />
<column name="COD_PRESTAMO" />
</key-many-to-one>
<key-many-to-one class="Sdec_monedaInfo"
column="COD_MONEDA"
name="codMoneda" />
<key-property column="COD_AMORTIZACION"
name="codAmortizacion"
type="integer" />
</composite-id>
...


Code between sessionFactory.openSession() and session.close(): Manage by spring framework

Full stack trace of any exception that occurs:
Sometimes it just ask for a property of this composite-id... for example:

net.sf.hibernate.PropertyNotFoundException: Could not find a setter for property codSector in class server.Sdem_pago_interesesPK
at net.sf.hibernate.property.BasicPropertyAccessor.getSetter(BasicPropertyAccessor.java:131)
at net.sf.hibernate.mapping.Property.getSetter(Property.java:178)
at net.sf.hibernate.cfg.Binder.bindComponent(Binder.java:894)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:287)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1243)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:249)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:285)
at org.springframework.orm.hibernate.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:322)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:948)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:284)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:204)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:136)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:203)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:279)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:81)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:57)
at cr.go.ice.sde.prueba.Prueba.main(Prueba.java:23)
Exception in thread "main" b]

[b]Name and version of the database you are using: Sybase


Debug level Hibernate log excerpt: NA

this is the stage:

Table = Sector
Atributes = cod_sector (pk)
sector

Table = Prestamo
Atributes = cod_prestamo (PK)
cod_sector (FK Sector) (PK)
montoPrestamo

Table = Amortizacion
Atributes = cod_amortizacion (PK)
cod_prestamo (FK Prestamo)(PK)
cod_sector (FK Prestamo - FK Sector) (PK)
fecha_amortizacion

So my problem is that I don


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 17, 2004 5:33 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
<composite-id class="Sdem_prestamoPK" name="id">


show this class code andbeware of the java naming convention ... should be Sdem_prestamoPK

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: Sdem_prestamoPK
PostPosted: Tue Aug 17, 2004 5:39 pm 
Newbie

Joined: Fri Dec 19, 2003 1:31 pm
Posts: 12
Yes Im aware of the Java convention related to class names, but this was created with the Hibernate syncronizer so... but that is not the issue....

Sdem_prestamoPK.java
Code:
public class Sdem_prestamoPK implements Serializable {

   private int hashCode = Integer.MIN_VALUE;

   private Sdec_sectorInfo codSector;
   private java.lang.String codPrestamo;

   public Sdem_prestamoPK () {}
   
   public Sdem_prestamoPK (
      Sdec_sectorInfo codSector,
      java.lang.String codPrestamo) {

      this.setCodSector(codSector);
      this.setCodPrestamo(codPrestamo);
   }

   public Sdec_sectorInfo getCodSector () {
      return codSector;
   }

   public void setCodSector (Sdec_sectorInfo codSector) {
      hashCode = Integer.MIN_VALUE;
      this.codSector = codSector;
   }

   public java.lang.String getCodPrestamo () {
      return codPrestamo;
   }

   public void setCodPrestamo (java.lang.String codPrestamo) {
      hashCode = Integer.MIN_VALUE;
      this.codPrestamo = codPrestamo;
   }

   public boolean equals (Object obj) {
      if (null == obj) return false;
      if (!(obj instanceof Sdem_prestamoPK)) return false;
      else {
         Sdem_prestamoPK mObj = (Sdem_prestamoPK) obj;
         if (null != this.getCodSector() && null != mObj.getCodSector()) {
            if (!this.getCodSector().equals(mObj.getCodSector())) {
               return false;
            }
         }
         else {
            return false;
         }
         if (null != this.getCodPrestamo() && null != mObj.getCodPrestamo()) {
            if (!this.getCodPrestamo().equals(mObj.getCodPrestamo())) {
               return false;
            }
         }
         else {
            return false;
         }
         return true;
      }
   }

   public int hashCode () {
      if (Integer.MIN_VALUE == this.hashCode) {
         StringBuffer sb = new StringBuffer();
         if (null != this.getCodSector()) {
            sb.append(this.getCodSector().hashCode());
            sb.append(":");
         }
         else {
            return super.hashCode();
         }
         if (null != this.getCodPrestamo()) {
            sb.append(this.getCodPrestamo().hashCode());
            sb.append(":");
         }
         else {
            return super.hashCode();
         }
         this.hashCode = sb.toString().hashCode();
      }
      return this.hashCode;
   }

}


And this is Sdem_prestamoInfo.java

Code:
private int hashCode = Integer.MIN_VALUE;

   // primary key
   private Sdem_prestamoPK id;

   // fields
   private java.lang.Integer periodoDesemb;
   private java.lang.Integer montoPrestamo;
   private java.lang.Integer tipoTasaInteres;
   private java.util.Date fechaUltDesemb;
   private java.lang.Integer porcApElectrico;
   private java.util.Date fechaVencCuota;
   private java.util.Date fechaVigencia;
   private java.lang.Integer periodoGracia;
   private java.lang.Integer montoDonacion;
   private java.util.Date fechaPrimDesemb;
   private java.lang.String finalidad;
   private java.lang.String observaciones;
   private java.lang.String basesAnuales;
   private java.lang.String nomPrestamo;
   private java.util.Date fechaContrato;
   private java.util.Date fechaInicAmort;
   private java.lang.Integer periodoTotal;
   private java.lang.Integer estado;
   private java.lang.Integer porcApTelecomun;
   private java.lang.String tasaInteres;
   private java.util.Date fechaVenc;
   private java.lang.Integer periodoAmort;

   // many to one
   private Sdec_tipo_financiamientoInfo codTipoFinanciamiento;
   private Sdec_tipo_periodoInfo codTipoPeriodo;
   private Sdec_monedaInfo codMoneda;
   private Sdec_acreedorInfo codAcreedor;


   // constructors
   public Sdem_prestamoInfo () {}

   /**
    * Constructor for primary key
    */
   public Sdem_prestamoInfo (Sdem_prestamoPK id) {
      this.setId(id);
   }

   /**
    * Constructor for required fields
    */
   public Sdem_prestamoInfo (
      Sdem_prestamoPK id,
      Sdec_tipo_financiamientoInfo codTipoFinanciamiento,
      Sdec_tipo_periodoInfo codTipoPeriodo,
      Sdec_monedaInfo codMoneda,
      Sdec_acreedorInfo codAcreedor) {

      this.setId(id);
      this.setCodTipoFinanciamiento(codTipoFinanciamiento);
      this.setCodTipoPeriodo(codTipoPeriodo);
      this.setCodMoneda(codMoneda);
      this.setCodAcreedor(codAcreedor);
   }

   /**
    * Return the unique identifier of this class
     * @hibernate.id
     */
   public Sdem_prestamoPK getId () {
      return id;
   }

   /**
    * Set the unique identifier of this class
    * @param id the new ID
    */
   public void setId (Sdem_prestamoPK id) {
      this.id = id;
      this.hashCode = Integer.MIN_VALUE;
   }

   /**
    * Return the value associated with the column: PERIODODESEMB
    */
   public java.lang.Integer getPeriodoDesemb () {
      return periodoDesemb;
   }

   /**
    * Set the value related to the column: PERIODODESEMB
    * @param periodoDesemb the PERIODODESEMB value
    */
   public void setPeriodoDesemb (java.lang.Integer periodoDesemb) {
      this.periodoDesemb = periodoDesemb;
   }
... getters and setter.. hash code and equals...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 17, 2004 5:48 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
1- the stacktrace is talking about class Sdem_pago_interesesPK, what is this? i suppose a class used to manage a composite-id , but where it is used? by which class? which mapping file, i can't see it (but i'm very busy too lol)

2-
Quote:
Yes Im aware of the Java convention related to class names, but this was created with the Hibernate syncronizer so... but that is not the issue....
--> uugh!

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: Sdem_pagoIntereses
PostPosted: Tue Aug 17, 2004 5:54 pm 
Newbie

Joined: Fri Dec 19, 2003 1:31 pm
Posts: 12
SdemPagoIntereses.java
Code:
<hibernate-mapping package="cr.go.ice.sde.domain">
   <class name="Sdem_pago_interesesInfo" table="SDEM_PAGO_INTERESES">
      <composite-id class="Sdem_pago_interesesPK" name="id">
         <key-many-to-one class="Sdem_prestamoPK" name="id">
            <column name="COD_SECTOR" />
            <column name="COD_PRESTAMO" />
         </key-many-to-one>
         <key-many-to-one
            class="Sdec_monedaInfo"
            column="COD_MONEDA"
            name="codMoneda"
          />
         <key-property
            column="COD_PAGOINTERES"
            name="codPagointeres"
            type="integer"
          />
      </composite-id>
      <property .....


Sdem_interesesInfo.java
Code:
private int hashCode = Integer.MIN_VALUE;

   // primary key
   private Sdem_pago_interesesPK id;

   // fields
   private java.lang.Integer montoMoneda;
   private java.lang.Integer estado;
   private java.lang.Integer tipoCambio;
   private java.lang.String observaciones;
   private java.lang.Integer montoDolares;
   private java.util.Date fechaPagointeres;

   // constructors
   public Sdem_pago_interesesInfo () {}

   /**
    * Constructor for primary key
    */
   public Sdem_pago_interesesInfo (Sdem_pago_interesesPK id) {
      this.setId(id);
   }

   /**
    * Return the unique identifier of this class
     * @hibernate.id
     */
   public Sdem_pago_interesesPK getId () {
      return id;
   }

   /**
    * Set the unique identifier of this class
    * @param id the new ID
    */
   public void setId (Sdem_pago_interesesPK id) {
      this.id = id;
      this.hashCode = Integer.MIN_VALUE;
   }

   /**
    * Return the value associated with the column: MONTOMONEDA
    */
   public java.lang.Integer getMontoMoneda () {
      return montoMoneda;
   }
....


And Pago_interesesPK which is used by the Pago_interesesInfo as PK.

Code:

public class Sdem_pago_interesesPK implements Serializable {

   private int hashCode = Integer.MIN_VALUE;

   private Sdem_prestamoPK id;
   private Sdec_monedaInfo codMoneda;
   private java.lang.Integer codPagointeres;

   public Sdem_pago_interesesPK () {}
   
   /**
    * @return Returns the idPrestamo.
    */
   public Sdem_prestamoPK getId() {
      return id;
   }
   /**
    * @param id The idPrestamo to set.
    */
   public void setId(Sdem_prestamoPK id) {
      this.id = id;
   }
   public Sdem_pago_interesesPK (
      Sdem_prestamoPK id,
      Sdec_monedaInfo codMoneda,
      java.lang.Integer codPagointeres) {

      this.setId(id);
      this.setCodMoneda(codMoneda);
      this.setCodPagointeres(codPagointeres);
   }

   public Sdec_monedaInfo getCodMoneda () {
      return codMoneda;
   }

   public void setCodMoneda (Sdec_monedaInfo codMoneda) {
      hashCode = Integer.MIN_VALUE;
      this.codMoneda = codMoneda;
   }
...



Thats it.. is another relashionship like the one between Prestamo and Amortizacion.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 17, 2004 6:06 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
1- the stacktrace:
Quote:
net.sf.hibernate.PropertyNotFoundException: Could not find a setter for property codSector in class server.Sdem_pago_interesesPK

2- the Sdem_pago_interesesPK mapping file
there is no codSector property declared in it

so please, go step by step and test it again

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 17, 2004 6:19 pm 
Newbie

Joined: Fri Dec 19, 2003 1:31 pm
Posts: 12
Right I know that, but this property should not be here... because it is in the id property which is:
Code:
<composite-id class="Sdem_pago_interesesPK" name="id">
         <key-many-to-one class="Sdem_prestamoPK" name="id">
            <column name="COD_SECTOR" />
            <column name="COD_PRESTAMO" />
         </key-many-to-one>


that's why in the Sdem_pagoInteresesInfo there is a getter/setter of id which is a Sdem_prestamoPK type and this is made of cod_sector and cod_prestamo... thats why to add a getter/setter to cod_sector is not right.

thanks for helping me out....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 23, 2004 8:04 pm 
Newbie

Joined: Fri Dec 19, 2003 1:31 pm
Posts: 12
any other help, or idea?


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