javax.persistence.EntityManager.detach()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(767)

本文整理了Java中javax.persistence.EntityManager.detach()方法的一些代码示例,展示了EntityManager.detach()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EntityManager.detach()方法的具体详情如下:
包路径:javax.persistence.EntityManager
类名称:EntityManager
方法名:detach

EntityManager.detach介绍

[英]Remove the given entity from the persistence context, causing a managed entity to become detached. Unflushed changes made to the entity if any (including removal of the entity), will not be synchronized to the database. Entities which previously referenced the detached entity will continue to reference it.
[中]从持久性上下文中删除给定实体,导致托管实体分离。对实体所做的未刷新更改(如果有)(包括删除实体)将不会同步到数据库。先前引用分离实体的实体将继续引用它。

代码示例

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
  public void detach(StructuredContent sc) {
    em.detach(sc);
  }
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
public void detachPage(Page page) {
  em.detach(page);
}

代码示例来源:origin: rapidoid/rapidoid

@Override
public void detach(Object entity) {
  em.detach(entity);
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
public void detach(Serializable entity) {
  standardEntityManager.detach(entity);
}

代码示例来源:origin: rapidoid/rapidoid

public void detach(final Object entity) {
  em.detach(entity);
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

@Override
public StaticAsset addOrUpdateStaticAsset(StaticAsset asset, boolean clearLevel1Cache) {
  if (clearLevel1Cache) {
    em.detach(asset);
  }
  return em.merge(asset);
}

代码示例来源:origin: rapidoid/rapidoid

@Override
public void detach(Object entity) {
  em().detach(entity);
}

代码示例来源:origin: spring-projects/spring-batch

List<T> queryResult = query.getResultList();
for (T entity : queryResult) {
  entityManager.detach(entity);
  results.add(entity);

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

protected void cleanupFailedPersistenceAttempt(Serializable instance) throws IllegalAccessException {
  //Remove the entity from ORM management - no further attempts to persist
  if (getPersistenceManager().getDynamicEntityDao().getStandardEntityManager().contains(instance)) {
    getPersistenceManager().getDynamicEntityDao().getStandardEntityManager().detach(instance);
  }
  //Remove the id field value, if it's set
  String idFieldName = (String) getPersistenceManager().getDynamicEntityDao().getIdMetadata(instance.getClass()).get("name");
  Field idField = FieldUtils.getField(instance.getClass(), idFieldName, true);
  if (idField == null) {
    throw ExceptionHelper.refineException(new NoSuchFieldException("Entity " + instance.getClass().getName() + " does not contain id field " + idFieldName));
  }
  idField.setAccessible(true);
  if (idField.get(instance) != null) {
    idField.set(instance, null);
  }
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

em.detach(cloneSku);
cloneSku.setId(null);
em.detach(cloneProduct);
cloneProduct.setId(null);
Product derivedProduct = catalogService.saveProduct(cloneProduct);
  em.detach(additionalSku);
  additionalSku.setId(null);
  additionalSku.setProduct(derivedProduct);

代码示例来源:origin: hibernate/hibernate-orm

.getResultList()) {
dtos.add(toDTO(person));
entityManager.detach( person );

代码示例来源:origin: stackoverflow.com

public interface UserRepositoryCustom {
  ...
  void detachUser(User u);
  ...
}

public interface UserRepository extends JpaRepository<User, Long>, UserRepositoryCustom {
  ...
}

@Repository
public class UserRepositoryCustomImpl implements UserRepositoryCustom {
  ...
  @PersistenceContext
  private EntityManager entityManager;

  @Override
  public void detachUser(User u) {
    entityManager.detach(u);
  }
  ...
}

代码示例来源:origin: hibernate/hibernate-orm

assertTrue( entityManager.contains( phone ));
entityManager.detach( person );

代码示例来源:origin: hibernate/hibernate-orm

assertTrue( entityManager.contains( phone ) );
entityManager.detach( person );

代码示例来源:origin: Impetus/Kundera

@Test
public void testRefresh() throws Exception
{
  Object p1 = prepareData("1", 10);
  Object p2 = prepareData("2", 20);
  Object p3 = prepareData("3", 15);
  em.persist(p1);
  em.persist(p2);
  em.persist(p3);
  // Check for contains
  Object pp1 = prepareData("1", 10);
  Object pp2 = prepareData("2", 20);
  Object pp3 = prepareData("3", 15);
  Assert.assertTrue(em.contains(pp1));
  Assert.assertTrue(em.contains(pp2));
  Assert.assertTrue(em.contains(pp3));
  // Check for detach
  em.detach(pp1);
  em.detach(pp2);
  Assert.assertFalse(em.contains(pp1));
  Assert.assertFalse(em.contains(pp2));
  Assert.assertTrue(em.contains(pp3));
  // Modify value in database directly, refresh and then check PC
  em.clear();
  em = emf.createEntityManager();
  Object o1 = em.find(Person.class, "1");
  em.refresh(o1);
  Object oo1 = em.find(Person.class, "1");
  Assert.assertTrue(em.contains(o1));
}

代码示例来源:origin: Impetus/Kundera

Assert.assertEquals("Singapore", found2.getCity());
em.detach(foundAfterMerge);
em.clear();
found = em.find(SampleEntity.class, 1);

代码示例来源:origin: Impetus/Kundera

entityManager.detach(pp1);
entityManager.detach(pp2);
Assert.assertFalse(entityManager.contains(pp1));
Assert.assertFalse(entityManager.contains(pp2));

代码示例来源:origin: Impetus/Kundera

entityManager.detach(pp1);
entityManager.detach(pp2);
Assert.assertFalse(entityManager.contains(pp1));
Assert.assertFalse(entityManager.contains(pp2));

代码示例来源:origin: Impetus/Kundera

em.detach(pp1);
em.detach(pp2);
Assert.assertFalse(em.contains(pp1));
Assert.assertFalse(em.contains(pp2));

代码示例来源:origin: Impetus/Kundera

em.detach(pp1);
em.detach(pp2);
Assert.assertFalse(em.contains(pp1));
Assert.assertFalse(em.contains(pp2));

相关文章