当前位置: 首页>>代码示例>>Java>>正文


Java EntityManager.getReference方法代码示例

本文整理汇总了Java中javax.persistence.EntityManager.getReference方法的典型用法代码示例。如果您正苦于以下问题:Java EntityManager.getReference方法的具体用法?Java EntityManager.getReference怎么用?Java EntityManager.getReference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.persistence.EntityManager的用法示例。


在下文中一共展示了EntityManager.getReference方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: destroy

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void destroy(String id) throws IllegalOrphanException, NonexistentEntityException, RollbackFailureException, Exception {
    EntityManager em = null;
    try {
        utx.begin();
        em = getEntityManager();
        Propietario propietario;
        try {
            propietario = em.getReference(Propietario.class, id);
            propietario.getCedula();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The propietario with id " + id + " no longer exists.", enfe);
        }
        List<String> illegalOrphanMessages = null;
        Collection<Telefono> telefonoCollectionOrphanCheck = propietario.getTelefonoCollection();
        for (Telefono telefonoCollectionOrphanCheckTelefono : telefonoCollectionOrphanCheck) {
            if (illegalOrphanMessages == null) {
                illegalOrphanMessages = new ArrayList<String>();
            }
            illegalOrphanMessages.add("This Propietario (" + propietario + ") cannot be destroyed since the Telefono " + telefonoCollectionOrphanCheckTelefono + " in its telefonoCollection field has a non-nullable propietarioId field.");
        }
        if (illegalOrphanMessages != null) {
            throw new IllegalOrphanException(illegalOrphanMessages);
        }
        em.remove(propietario);
        utx.commit();
    } catch (Exception ex) {
        try {
            utx.rollback();
        } catch (Exception re) {
            throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
        }
        throw ex;
    } finally {
        if (em != null) {
            em.close();
        }
    }
}
 
开发者ID:AmauryOrtega,项目名称:Sem-Update,代码行数:39,代码来源:PropietarioJpaController.java

示例2: create

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void create(Telefono telefono) throws RollbackFailureException, Exception {
    EntityManager em = null;
    try {
        utx.begin();
        em = getEntityManager();
        Propietario propietarioId = telefono.getPropietarioId();
        if (propietarioId != null) {
            propietarioId = em.getReference(propietarioId.getClass(), propietarioId.getCedula());
            telefono.setPropietarioId(propietarioId);
        }
        em.persist(telefono);
        if (propietarioId != null) {
            propietarioId.getTelefonoCollection().add(telefono);
            propietarioId = em.merge(propietarioId);
        }
        utx.commit();
    } catch (Exception ex) {
        try {
            utx.rollback();
        } catch (Exception re) {
            throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
        }
        throw ex;
    } finally {
        if (em != null) {
            em.close();
        }
    }
}
 
开发者ID:AmauryOrtega,项目名称:Sem-Update,代码行数:30,代码来源:TelefonoJpaController.java

示例3: destroy

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void destroy(Integer id) throws NonexistentEntityException, RollbackFailureException, Exception {
    EntityManager em = null;
    try {
        utx.begin();
        em = getEntityManager();
        Telefono telefono;
        try {
            telefono = em.getReference(Telefono.class, id);
            telefono.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The telefono with id " + id + " no longer exists.", enfe);
        }
        Propietario propietarioId = telefono.getPropietarioId();
        if (propietarioId != null) {
            propietarioId.getTelefonoCollection().remove(telefono);
            propietarioId = em.merge(propietarioId);
        }
        em.remove(telefono);
        utx.commit();
    } catch (Exception ex) {
        try {
            utx.rollback();
        } catch (Exception re) {
            throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
        }
        throw ex;
    } finally {
        if (em != null) {
            em.close();
        }
    }
}
 
开发者ID:AmauryOrtega,项目名称:Sem-Update,代码行数:33,代码来源:TelefonoJpaController.java

示例4: destroy

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void destroy(String _id) throws NonexistentEntityException, RollbackFailureException, Exception {
    EntityManager em = null;
    try {
        utx.begin();
        em = getEntityManager();
        Usuario user;
        try {
            user = em.getReference(Usuario.class, _id);
            user.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The persona with id " + _id + " no longer exists.", enfe);
        }
        em.remove(user);
        utx.commit();
    } catch (Exception ex) {
        try {
            utx.rollback();
        } catch (Exception re) {
            throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
        }
        throw ex;
    } finally {
        if (em != null) {
            em.close();
        }
    }
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:28,代码来源:UsuarioJpaController.java

示例5: create

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void create(Propietario propietario) throws PreexistingEntityException, RollbackFailureException, Exception {
    if (propietario.getTelefonoCollection() == null) {
        propietario.setTelefonoCollection(new ArrayList<Telefono>());
    }
    EntityManager em = null;
    try {
        utx.begin();
        em = getEntityManager();
        Collection<Telefono> attachedTelefonoCollection = new ArrayList<Telefono>();
        for (Telefono telefonoCollectionTelefonoToAttach : propietario.getTelefonoCollection()) {
            telefonoCollectionTelefonoToAttach = em.getReference(telefonoCollectionTelefonoToAttach.getClass(), telefonoCollectionTelefonoToAttach.getId());
            attachedTelefonoCollection.add(telefonoCollectionTelefonoToAttach);
        }
        propietario.setTelefonoCollection(attachedTelefonoCollection);
        em.persist(propietario);
        for (Telefono telefonoCollectionTelefono : propietario.getTelefonoCollection()) {
            Propietario oldPropietarioIdOfTelefonoCollectionTelefono = telefonoCollectionTelefono.getPropietarioId();
            telefonoCollectionTelefono.setPropietarioId(propietario);
            telefonoCollectionTelefono = em.merge(telefonoCollectionTelefono);
            if (oldPropietarioIdOfTelefonoCollectionTelefono != null) {
                oldPropietarioIdOfTelefonoCollectionTelefono.getTelefonoCollection().remove(telefonoCollectionTelefono);
                oldPropietarioIdOfTelefonoCollectionTelefono = em.merge(oldPropietarioIdOfTelefonoCollectionTelefono);
            }
        }
        utx.commit();
    } catch (Exception ex) {
        try {
            utx.rollback();
        } catch (Exception re) {
            throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
        }
        if (findPropietario(propietario.getCedula()) != null) {
            throw new PreexistingEntityException("Propietario " + propietario + " already exists.", ex);
        }
        throw ex;
    } finally {
        if (em != null) {
            em.close();
        }
    }
}
 
开发者ID:AmauryOrtega,项目名称:Sem-Update,代码行数:42,代码来源:PropietarioJpaController.java

示例6: edit

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void edit(Propietario propietario) throws IllegalOrphanException, NonexistentEntityException, RollbackFailureException, Exception {
    EntityManager em = null;
    try {
        utx.begin();
        em = getEntityManager();
        Propietario persistentPropietario = em.find(Propietario.class, propietario.getCedula());
        Collection<Telefono> telefonoCollectionOld = persistentPropietario.getTelefonoCollection();
        Collection<Telefono> telefonoCollectionNew = propietario.getTelefonoCollection();
        List<String> illegalOrphanMessages = null;
        for (Telefono telefonoCollectionOldTelefono : telefonoCollectionOld) {
            if (!telefonoCollectionNew.contains(telefonoCollectionOldTelefono)) {
                if (illegalOrphanMessages == null) {
                    illegalOrphanMessages = new ArrayList<String>();
                }
                illegalOrphanMessages.add("You must retain Telefono " + telefonoCollectionOldTelefono + " since its propietarioId field is not nullable.");
            }
        }
        if (illegalOrphanMessages != null) {
            throw new IllegalOrphanException(illegalOrphanMessages);
        }
        Collection<Telefono> attachedTelefonoCollectionNew = new ArrayList<Telefono>();
        for (Telefono telefonoCollectionNewTelefonoToAttach : telefonoCollectionNew) {
            telefonoCollectionNewTelefonoToAttach = em.getReference(telefonoCollectionNewTelefonoToAttach.getClass(), telefonoCollectionNewTelefonoToAttach.getId());
            attachedTelefonoCollectionNew.add(telefonoCollectionNewTelefonoToAttach);
        }
        telefonoCollectionNew = attachedTelefonoCollectionNew;
        propietario.setTelefonoCollection(telefonoCollectionNew);
        propietario = em.merge(propietario);
        for (Telefono telefonoCollectionNewTelefono : telefonoCollectionNew) {
            if (!telefonoCollectionOld.contains(telefonoCollectionNewTelefono)) {
                Propietario oldPropietarioIdOfTelefonoCollectionNewTelefono = telefonoCollectionNewTelefono.getPropietarioId();
                telefonoCollectionNewTelefono.setPropietarioId(propietario);
                telefonoCollectionNewTelefono = em.merge(telefonoCollectionNewTelefono);
                if (oldPropietarioIdOfTelefonoCollectionNewTelefono != null && !oldPropietarioIdOfTelefonoCollectionNewTelefono.equals(propietario)) {
                    oldPropietarioIdOfTelefonoCollectionNewTelefono.getTelefonoCollection().remove(telefonoCollectionNewTelefono);
                    oldPropietarioIdOfTelefonoCollectionNewTelefono = em.merge(oldPropietarioIdOfTelefonoCollectionNewTelefono);
                }
            }
        }
        utx.commit();
    } catch (Exception ex) {
        try {
            utx.rollback();
        } catch (Exception re) {
            throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
        }
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            String id = propietario.getCedula();
            if (findPropietario(id) == null) {
                throw new NonexistentEntityException("The propietario with id " + id + " no longer exists.");
            }
        }
        throw ex;
    } finally {
        if (em != null) {
            em.close();
        }
    }
}
 
开发者ID:AmauryOrtega,项目名称:Sem-Update,代码行数:61,代码来源:PropietarioJpaController.java

示例7: edit

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public void edit(Telefono telefono) throws NonexistentEntityException, RollbackFailureException, Exception {
    EntityManager em = null;
    try {
        utx.begin();
        em = getEntityManager();
        Telefono persistentTelefono = em.find(Telefono.class, telefono.getId());
        Propietario propietarioIdOld = persistentTelefono.getPropietarioId();
        Propietario propietarioIdNew = telefono.getPropietarioId();
        if (propietarioIdNew != null) {
            propietarioIdNew = em.getReference(propietarioIdNew.getClass(), propietarioIdNew.getCedula());
            telefono.setPropietarioId(propietarioIdNew);
        }
        telefono = em.merge(telefono);
        if (propietarioIdOld != null && !propietarioIdOld.equals(propietarioIdNew)) {
            propietarioIdOld.getTelefonoCollection().remove(telefono);
            propietarioIdOld = em.merge(propietarioIdOld);
        }
        if (propietarioIdNew != null && !propietarioIdNew.equals(propietarioIdOld)) {
            propietarioIdNew.getTelefonoCollection().add(telefono);
            propietarioIdNew = em.merge(propietarioIdNew);
        }
        utx.commit();
    } catch (Exception ex) {
        try {
            utx.rollback();
        } catch (Exception re) {
            throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
        }
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = telefono.getId();
            if (findTelefono(id) == null) {
                throw new NonexistentEntityException("The telefono with id " + id + " no longer exists.");
            }
        }
        throw ex;
    } finally {
        if (em != null) {
            em.close();
        }
    }
}
 
开发者ID:AmauryOrtega,项目名称:Sem-Update,代码行数:43,代码来源:TelefonoJpaController.java

示例8: getGuestById

import javax.persistence.EntityManager; //导入方法依赖的package包/类
public Guest getGuestById(Long id) {
    EntityManager entityManager = HibernateUtil.getEntityManager();
    Guest guest = entityManager.getReference(Guest.class, id);
    entityManager.close();
    return guest;
}
 
开发者ID:maillouxc,项目名称:git-rekt,代码行数:7,代码来源:GuestService.java


注:本文中的javax.persistence.EntityManager.getReference方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。