}
try {
Session currentSession = getSession();
currentSession.clear();
Recurso entity = null;
if (p.getId() == null
|| (p.getId() != null && this.get(p.getId()) == null)) {
entity = p;
} else {
entity = (Recurso) currentSession.merge(p);
if (p.getEstadoEurocop() != null
&& p.getEstadoEurocop().getId() != null) {
entity.setEstadoEurocop((EstadoRecurso) currentSession.get(
EstadoRecurso.class, p.getEstadoEurocop().getId()));
}
}
if (entity == null) {
entity = p;
}
if (entity != null) {
entity.setInfoAdicional(p.getInfoAdicional());
entity.setNombre(p.getNombre());
}
Patrulla patrulla = null;
if (p.getPatrullas() != null) {
if (p.getPatrullas().getId() != null) {
patrulla = (Patrulla) currentSession.load(Patrulla.class, p
.getPatrullas().getId());
} else {
patrulla = p.getPatrullas();
}
}
entity.setPatrullas(patrulla);
if (entity.getEstadoEurocop() == null) {
entity.setEstadoEurocop((EstadoRecurso) currentSession.get(
EstadoRecurso.class, 1l));
}
entity.setIdentificador(entity.getNombre());
currentSession.saveOrUpdate(entity);
} catch (Throwable t) {
log.error(t, t);
}
return true;