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

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

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

EntityManager.getEntityGraph介绍

[英]Return a named EntityGraph. The returned EntityGraph should be considered immutable.
[中]返回一个命名的EntityGraph。返回的EntityGraph应视为不可变。

代码示例

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

@Override
public EntityGraph<?> getEntityGraph(String graphName) {
  return em.getEntityGraph(graphName);
}

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

@Override
public EntityGraph<?> getEntityGraph(String graphName) {
  return em().getEntityGraph(graphName);
}

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

/**
 * Adds a JPA 2.1 fetch-graph or load-graph hint to the given {@link Query} if running under JPA 2.1.
 *
 * @see <a href="download.oracle.com/otn-pub/jcp/persistence-2_1-fr-eval-spec/JavaPersistence.pdf">JPA 2.1
 *      Specfication 3.7.4 - Use of Entity Graphs in find and query operations P.117</a>
 * @param em must not be {@literal null}.
 * @param jpaEntityGraph must not be {@literal null}.
 * @param entityType must not be {@literal null}.
 * @return the {@link EntityGraph} described by the given {@code entityGraph}.
 */
@Nullable
private static EntityGraph<?> tryGetFetchGraph(EntityManager em, JpaEntityGraph jpaEntityGraph, Class<?> entityType) {
  Assert.notNull(em, "EntityManager must not be null!");
  Assert.notNull(jpaEntityGraph, "EntityGraph must not be null!");
  Assert.notNull(entityType, "EntityType must not be null!");
  Assert.isTrue(JPA21_AVAILABLE, "The EntityGraph-Feature requires at least a JPA 2.1 persistence provider!");
  Assert.isTrue(GET_ENTITY_GRAPH_METHOD != null,
      "It seems that you have the JPA 2.1 API but a JPA 2.0 implementation on the classpath!");
  try {
    // first check whether an entityGraph with that name is already registered.
    return em.getEntityGraph(jpaEntityGraph.getName());
  } catch (Exception ex) {
    // try to create and dynamically register the entityGraph
    return createDynamicEntityGraph(em, jpaEntityGraph, entityType);
  }
}

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

Collections.singletonMap(
  "javax.persistence.fetchgraph",
  entityManager.getEntityGraph( "employee.projects" )
Collections.singletonMap(
  "javax.persistence.fetchgraph",
  entityManager.getEntityGraph( "project.employees" )

代码示例来源:origin: org.evolvis.bsi/kolab-ws

@Override
public EntityGraph<?>
getEntityGraph(String graphName)
{
  return delegate.getEntityGraph(graphName);
}

代码示例来源:origin: EvoSuite/evosuite

@Override
public EntityGraph<?> getEntityGraph(String graphName) {
  return em.getEntityGraph(graphName);
}

代码示例来源:origin: kumuluz/kumuluzee

@Override
public EntityGraph<?> getEntityGraph(String graphName) {
  return em.getEntityGraph(graphName);
}

代码示例来源:origin: com.phloc/phloc-db

public EntityGraph <?> getEntityGraph (final String graphName)
{
 return m_aEntityMgr.getEntityGraph (graphName);
}

代码示例来源:origin: org.jboss.eap/wildfly-jpa

@Override
public EntityGraph<?> getEntityGraph(String graphName) {
  return entityManager.getEntityGraph(graphName);
}

代码示例来源:origin: com.helger/ph-db-jpa

public EntityGraph <?> getEntityGraph (final String graphName)
{
 return m_aEntityMgr.getEntityGraph (graphName);
}

代码示例来源:origin: org.omnifaces/omnipersistence

/**
 * Get entity by the given ID and entity graph name.
 * @param id Entity ID to get entity by.
 * @param entityGraphName Entity graph name.
 * @return Found entity, or <code>null</code> if there is none.
 */
public E getByIdWithLoadGraph(I id, String entityGraphName) {
  EntityGraph<?> entityGraph = entityManager.getEntityGraph(entityGraphName);
  Map<String, Object> properties = new HashMap<>();
  properties.put(QUERY_HINT_LOAD_GRAPH, entityGraph);
  properties.put(QUERY_HINT_CACHE_RETRIEVE_MODE, BYPASS);
  return getEntityManager().find(entityType, id, properties);
}

代码示例来源:origin: net.oneandone/ejb-cdi-unit

@Override
public EntityGraph<?> getEntityGraph(String graphName) {
  return getEmbeddedEntityManager().getEntityGraph(graphName);
}

代码示例来源:origin: br.com.jarch/jarch-crud

private Map<String, Object> getMapFetchGraph(String graphName) {
  Map<String, Object> map = new HashMap<>();
  map.put(HINT_FETCHGRAPH, getEntityManager().getEntityGraph(graphName));
  return map;
}

代码示例来源:origin: br.com.jarch/jarch-crud

private Map<String, Object> getMapLoadGraph(String graphName) {
  Map<String, Object> map = new HashMap<>();
  map.put(HINT_LOADGRAPH, getEntityManager().getEntityGraph(graphName));
  return map;
}

代码示例来源:origin: com.carecon.fabric3/fabric3-jpa-hibernate

public EntityGraph<?> getEntityGraph(String graphName) {
  initEntityManager();
  return em.getEntityGraph(graphName);
}

代码示例来源:origin: org.wildfly/wildfly-jpa

public EntityGraph<?> getEntityGraph(String s) {
  long start = 0;
  if (isTraceEnabled)
    start = System.currentTimeMillis();
  try {
    return getEntityManager().getEntityGraph(s);
  } finally {
    if (isTraceEnabled) {
      long elapsed = System.currentTimeMillis() - start;
      ROOT_LOGGER.tracef("getEntityGraph %s took %dms", s, elapsed);
    }
  }
}

代码示例来源:origin: org.apache.tomee/openejb-core

@Override
public EntityGraph<?> getEntityGraph(final String graphName) {
  final Timer timer = Op.getEntityGraph.start(this.timer, this);
  try {
    return getEntityManager().getEntityGraph(graphName);
  } finally {
    timer.stop();
  }
}

代码示例来源:origin: pramoth/specification-with-projection

@Override
public <R> Page<R> findAll(Specification<T> spec, Class<R> projectionType, String namedEntityGraph, org.springframework.data.jpa.repository.EntityGraph.EntityGraphType type, Pageable pageable) {
  EntityGraph<?> entityGraph = this.entityManager.getEntityGraph(namedEntityGraph);
  if (entityGraph == null) {
    throw new IllegalArgumentException("Not found named entity graph -> " + namedEntityGraph);
  }
  TypedQuery<T> query = getQuery(spec, pageable);
  query.setHint(type.getKey(), entityGraph);
  return readPageWithProjection(spec, projectionType, pageable, query);
}

代码示例来源:origin: vladmihalcea/high-performance-java-persistence

@Test
public void testFindWithNamedEntityGraph() {
  doInJPA(entityManager -> {
    PostComment comment = entityManager.find(PostComment.class, 1L,
      Collections.singletonMap(
        "javax.persistence.fetchgraph",
        entityManager.getEntityGraph("PostComment.post")
      )
    );
    LOGGER.info("Fetch entity graph");
    assertNotNull(comment);
  });
}

代码示例来源:origin: org.glassfish.main.common/container-common

@Override
public EntityGraph<?> getEntityGraph(String graphName) {
  try {
    if(callFlowAgent.isEnabled()) {
      callFlowAgent.entityManagerMethodStart(EntityManagerMethod.GET_ENTITY_GRAPH);
    }
    return _getDelegate().getEntityGraph(graphName);
  } finally {
    if(callFlowAgent.isEnabled()) {
      callFlowAgent.entityManagerMethodEnd();
    }
  }
}

相关文章