Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.spring.model; import com.google.gson.Gson; import com.spring.entity.Sesion; import com.spring.entity.Signosvitales; import com.spring.entity.Tratamiento; import java.math.BigDecimal; import java.util.List; import java.util.Set; import org.hibernate.Criteria; import org.hibernate.Hibernate; import org.hibernate.Query; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; /** * * @author carlosantonio */ @Repository("tratamientoService") @Transactional public class TratamientoModel extends AbstractModel<BigDecimal, Tratamiento> { public Tratamiento findById(BigDecimal id) { Tratamiento tra = getByKey(id); /*if(tra!=null){ Hibernate.initialize(tra.getEmpleado()); Hibernate.initialize(tra.getExpediente()); Hibernate.initialize(tra.getExpediente().getPaciente()); Hibernate.initialize(tra.getExpediente().getPaciente().getPersona()); }*/ return tra; } public void saveTratamiento(Tratamiento tra) { persist(tra); } public void deleteExpedienteById(BigDecimal codTratamiento) { Query query = getSession() .createSQLQuery("delete from tratamiento where cod_tratamiento = :cod_tratamiento"); query.setBigDecimal("cod_tratamiento", codTratamiento); query.executeUpdate(); } public List<Sesion> findSesiones(BigDecimal id) { Tratamiento tra = getByKey(id); if (tra != null) { Hibernate.initialize(tra.getSesions()); return tra.getSesions(); } return null; } public List<Tratamiento> findAllTratamientos() { Criteria criteria = createEntityCriteria(); return (List<Tratamiento>) criteria.list(); } }