Hello again, I'm having some problems saving persisted data to a table. I don't know if this is the rigth place to post this doubt, I posted it in springframework forum too. If this isn't relate with hibernate forums, please feel free to delete this topic.
Well, Here I paste what I've wrote this morning in the spring forum:
{ // BEGIN POST
This excepction takes place when I want to do the save to the persisted object into the database (getHibernateTemplate().save(object)):
Exception thrown executing action 'es.tid.sgd.web.flow.rangerequest.RangeRequestAction@8caf5' in state 'viewInitRangeRequest' of flow 'rangeRequestFlow'; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance - save the transient instance before flushing: es.tid.sgd.model.bean.usuario.Usuario;
nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: es.tid.sgd.model.bean.usuario.Usuario
That means that something is wrong with that object (Usuario = user). Hibernate mapping is good cause I did a select searching (getHibernateTemplate().find("criteria")) for range requests and it returned to me all data that is in the table called Range Requests. So, if it could do a select, I think that a save should work too, shouldn't it?
The problem is when I get the object from the request this way:
RangeRequest rr = (RangeRequest) getFormObject(ctx); // ctx = context
rr have some attributes from the request, like name, size, managerUsers, but I don't get an attribute called requestUser who is that does the request.
To solve this, I thought that I could do something like this:
public void insert(Bean bean) {
SolicitudRango sr = (SolicitudRango) bean;
Usuario u=new Usuario();
u.setCodUsuario(14);
u.setApellidos("ORTEGA VARAS");
u.setNombre("AMAIA");
u.setLogin("amaia");
u.setTelefono("");
u.setTelefonoMovil("");
u.setCorreoElectronico("
[email protected]");
sr.setUsuarioSolicitante(u);
// Is here the problem??
getHibernateTemplate().save(sr);
}
But it seems that spring and hibernate do not like this way ...
I hope that now I gave you all the info you need to solve my 'big doubt'.
} // END POST
And the same for you,
Thanks in advance.
Miguel M.