Ver Mensaje Individual
  #4 (permalink)  
Antiguo 06/02/2013, 13:34
ARAPSPGON
 
Fecha de Ingreso: octubre-2007
Mensajes: 57
Antigüedad: 18 años, 11 meses
Puntos: 0
Respuesta: JPA Controladores de Entidades Relacionadas

puedo solucionarlo modificando el metodo destroy

Código PHP:
public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException {
        
EntityManager em = null;
        try {
            
em = getEntityManager();
            
em.getTransaction().begin();
            
Departamentos departamentos;
            try {
                
departamentos = em.getReference(Departamentos.class, id);
                
departamentos.getIddep();
            } catch (
EntityNotFoundException enfe) {
                throw new 
NonexistentEntityException("The departamentos with id " + id + " no longer exists.", enfe);
            }
            List<
String> illegalOrphanMessages = null;
            
Collection<Empleados> empleadosCollectionOrphanCheck = departamentos.getEmpleadosCollection();
            for (
Empleados empleadosCollectionOrphanCheckEmpleados : empleadosCollectionOrphanCheck) {
                
em.remove(empleadosCollectionOrphanCheckEmpleados);
//                if (illegalOrphanMessages == null) {
//                    illegalOrphanMessages = new ArrayList<String>();
//                }
//                illegalOrphanMessages.add("This Departamentos (" + departamentos + ") cannot be destroyed since the Empleados " + empleadosCollectionOrphanCheckEmpleados + " in its empleadosCollection field has a non-nullable iddep field.");
            
}
//            if (illegalOrphanMessages != null) {
//                throw new IllegalOrphanException(illegalOrphanMessages);
//            }
            
em.remove(departamentos);
            
em.getTransaction().commit();
        } 
finally {
            if (
em != null) {
                
em.close();
            }
        }
    } 
pero en dos tablas se hace rapido ...pero teniendo muuuchas tablas y muuchas relaciones de ese tipo la cosa se hace tediosa...no entiendo porque el método me lanza la excepción en vez de borrar el departamento y los empleados de este departamento..

se supone que la herramienta que tiene netbeans que genera las clases controller de las clases entidad agiliza la tarea y no la hace mas tediosa.