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 !!