code: @Test public void should_batch_several_entities() throws Exception {
    CompleteBean bean=CompleteBeanTestBuilder.builder().randomId().name("name").buid();
    Tweet tweet1=TweetTestBuilder.tweet().randomId().content("tweet1").buid();
    Tweet tweet2=TweetTestBuilder.tweet().randomId().content("tweet2").buid();
    Batch batchEm=pmf.createBatch();
    batchEm.startBatch();
    batchEm.persist(bean);
    batchEm.persist(tweet1);
    batchEm.persist(tweet2);
    batchEm.persist(user);
    CompleteBean foundBean=batchEm.find(CompleteBean.class,bean.getId());
    Tweet foundTweet1=batchEm.find(Tweet.class,tweet1.getId());
    Tweet foundTweet2=batchEm.find(Tweet.class,tweet2.getId());
    User foundUser=batchEm.find(User.class,user.getId());
    assertThat(foundBean).isNull();
    assertThat(foundTweet1).isNull();
    assertThat(foundTweet2).isNull();
    assertThat(foundUser).isNull();
    batchEm.endBatch();
    foundBean=batchEm.find(CompleteBean.class,bean.getId());
    foundTweet1=batchEm.find(Tweet.class,tweet1.getId());
    foundTweet2=batchEm.find(Tweet.class,tweet2.getId());
    foundUser=batchEm.find(User.class,user.getId());
    assertThat(foundBean.getName()).isEqualTo("name");
    assertThat(foundTweet1.getContent()).isEqualTo("tweet1");
    assertThat(foundTweet2.getContent()).isEqualTo("tweet2");
    assertThat(foundUser.getFirstname()).isEqualTo("fn");
    assertThat(foundUser.getLastname()).isEqualTo("ln");
    assertThatBatchContextHasBeenReset(batchEm);
  }
  