org.hibernate.query.NativeQuery.setFlushMode()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(3.1k)|赞(0)|评价(0)|浏览(171)

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

NativeQuery.setFlushMode介绍

暂无

代码示例

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

@Test
public void testFlushSQL() {
  doInJPA( this::entityManagerFactory, entityManager -> {
    entityManager.createNativeQuery("delete from Person").executeUpdate();
  });
  doInJPA( this::entityManagerFactory, entityManager -> {
    log.info("testFlushSQL");
    //tag::flushing-always-flush-sql-example[]
    Person person = new Person("John Doe");
    entityManager.persist(person);
    Session session = entityManager.unwrap( Session.class);
    assertTrue(((Number) session
        .createNativeQuery("select count(*) from Person")
        .setFlushMode( FlushMode.ALWAYS)
        .uniqueResult()).intValue() == 1);
    //end::flushing-always-flush-sql-example[]
  });
}

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

@Benchmark
@OperationsPerInvocation(OPERATIONS_PER_INVOCATION)
public void findEntityByPropertyUsingNativeQueryWithManualFlushing(TestDataInserter inserter, Blackhole blackhole) throws Exception {
  EntityManagerFactoryHolder stateHolder = inserter.stateHolder;
  EntityManager entityManager = stateHolder.entityManagerFactory.createEntityManager();
  stateHolder.transactionManager.begin();
  entityManager.joinTransaction();
  for ( int i = 0; i < OPERATIONS_PER_INVOCATION; i++ ) {
    int mName = stateHolder.rand.nextInt( 26 );
    Query nativeQuery = entityManager.createNativeQuery( "db.AuthorWithSequence.find( { 'mname' : '" + mName + "' } )", AuthorWithSequence.class );
    nativeQuery.unwrap( NativeQuery.class ).addSynchronizedEntityClass( AuthorWithSequence.class );
    nativeQuery.setMaxResults( 50 );
    nativeQuery.unwrap( NativeQuery.class ).setFlushMode( FlushMode.MANUAL );
    @SuppressWarnings("unchecked")
    List<AuthorWithSequence> authors = nativeQuery.getResultList();
    for ( AuthorWithSequence author : authors ) {
      blackhole.consume( author.getLname() );
    }
  }
  stateHolder.transactionManager.commit();
  entityManager.close();
}

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

@Test
public void testFlushAutoNativeSQLFlushModeAlways() {
  doInJPA(entityManager -> {
    assertEquals(
      0,
      ((Number)
        entityManager
        .createNativeQuery(
          "select count(*) " +
          "from post")
        .getSingleResult()
      ).intValue()
    );
    Post post = new Post("High-Performance Java Persistence");
    entityManager.persist(post);
    int postCount = ((Number)
    entityManager
    .unwrap(Session.class)
    .createNativeQuery(
      "select count(*) " +
      "from post")
    .setFlushMode(FlushMode.ALWAYS)
    .getSingleResult()).intValue();
    assertEquals(1, postCount);
  });
}

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

"JOIN board b on b.id = p.board_id " +
  "GROUP BY forum")
.setFlushMode(FlushMode.ALWAYS)
.setResultTransformer( Transformers.aliasToBean(ForumCount.class))
.list();

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

"JOIN board b on b.id = p.board_id " +
  "GROUP BY forum")
.setFlushMode(FlushMode.ALWAYS)
.setResultTransformer( Transformers.aliasToBean(ForumCount.class))
.list();

相关文章