Hello guys, i am newbie in hibernate and i am getting an error when teying to insert. I would apreciate some help.
I am using Hibernate 3.3
The error is:
object references an unsaved transient instance - save the transient instance before flushing: es.cyii.cyprehu.model.EstadoVO; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: es.cyii.cyprehu.model.EstadoVO
The idea is that a "ConsultaVO" can have a "EstadoVO" (Estate). The states are allready in the BBDD and it could be for example 1- Open, 2- Close.
I want to create a new Consulta in BBDD, without any Estate. then, after that, i want to be able to change the Estate to open, close, etc...
When i get a Consulta from BBDD, i want to recover the State, including the ID and the Description.
Probably i am making some things wrong.
The code is:
VOs:
Code:
public class ConsultaVO {
private Long idConsulta;
private EstadoVO estado;
...........getters and setters......
}
public class EstadoVO {
private Long idEstado;
private String descripcion;
...........getters and setters......
}
mappings
Code:
<class name="es.cyii.cyprehu.model.ConsultaVO" table="CONSULTAS">
<id name="idConsulta" type="long">
<column name="ID_CONSULTA"/>
<generator class="sequence">
<param name="sequence">seq_consultas</param>
</generator>
</id>
<many-to-one name="estado" column="ID_ESTADO"
class="es.cyii.cyprehu.model.EstadoVO"
lazy="false"/>
</class>
<class name="es.cyii.cyprehu.model.EstadoVO" table="ESTADOS">
<id name="idEstado" type="long">
<column name="ID_ESTADO"/>
<generator class="sequence">
<param name="sequence">seq_estados</param>
</generator>
</id>
<property name="descripcion" type="string">
<column name="DESCRIPCION"/>
</property>
</class>
DAO
Code:
public String insertConsulta (ConsultaVO consulta) throws Exception{
String result;
result = (String)getHibernateTemplate().save(consulta);
return result;
}
Any help please?
Thx you very much.