-->
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.  [ 1 post ] 
Author Message
 Post subject: composite-id problem: session.save do nothing
PostPosted: Mon Jun 02, 2008 11:01 am 
Newbie

Joined: Mon Jun 02, 2008 8:18 am
Posts: 2
Hi all,

I can`t save a persisted instance when using composite-id. This is the class:

Code:
public class SerieNumerica
{
 
  private Integer numero;
  private Id id;
 
  public SerieNumerica() {}
 
  public SerieNumerica(Long idEntidad, Integer anyo)
  {
    this.id = new Id(idEntidad, anyo);
  }

  public class Id implements Serializable
  {
    private Long idEntidad;
    private Integer anyo;
   
    public Id(Long idEntidad, Integer anyo)
    {
      this.idEntidad = idEntidad;
      this.anyo = anyo;
    }
   
    public Long getIdEntidad()
    {
      return idEntidad;
    }
   
    public void setIdEntidad(Long idEntidad)
    {
      this.idEntidad = idEntidad;
    }
   
    public Integer getAnyo()
    {
      return anyo;
    }
   
    public void setAnyo(Integer anyo)
    {
      this.anyo = anyo;
    }
   
    public boolean equals(Object o)
    {
      if (o instanceof Id)
      {
        if (((Id) o).idEntidad == this.idEntidad && ((Id) o).anyo == this.anyo)
          return true;
      }
      return false;
    }
   
    public int hashCode()
    {
      return (new Integer(this.idEntidad.intValue() * this.anyo.intValue())).hashCode();
    }
  }
 
... getters/setters
 
}


This is the mapping:


Code:
<class name="SerieNumerica" table="TA_SERIES_NUMERICAS" lazy="false">
        <composite-id name="id" class="SerieNumerica$Id">
           <key-property name="idEntidad" column="id_entidad"/>
           <key-property name="anyo"/>
        </composite-id>
        <property name="numero"/>
       
    </class>


And this is the code for updating:
Code:
SerieNumerica snNueva = new SerieNumerica(pk1, pk2);
sn = (SerieNumerica) sesion.load(SerieNumerica.class, snNueva.getId());
sn.setNumero(5345);
sesion.save(sn);


It doesn`t throw an exception, simply the session.save line DO NOTHING, not even print the SQL.

Of course the session.load line works fine.

Thanks !!


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

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.