Whilst the following method is called in a test case, run with
CdiTestRunner, the entityManager.flush() call causes a
TransactionRequiredException.

@Transactional
public void saveAndFetchUser() {
    // Given - a new user
    final User randomUser = createRandomUser(false);

   // When - saved
    final User savedUser = userService.saveUser(randomUser);
    // Then - user is saved as well as history and can be retrieved by id
and username
    assertThat(savedUser.getRoles(), hasSize(greaterThan(0)));

    entityManager.flush();  // manually flush as UaiCriteriaQueries aren't
flushed automatically
    final Paged<UserHistory> pagedHistory =
findUserHistoryMostRecentFirst(randomUser.getUsername());
    assertThat(pagedHistory.getDerivedTotal(), equalTo(1));
    assertThat(pagedHistory.getList(), hasSize(1));

    ...
}

Is this a bug, or is there another way to flush the changes to the database?

Environment:
weld: 2.3.1.Final
deltaspike: 1.5.1.Final
deltaspike dependencies

<dependency>

<groupId>org.apache.deltaspike.modules</groupId>

<artifactId>*deltaspike*-*jpa*-module-*api*</artifactId>

<version>${deltaspike.version}</version>

<scope>compile</scope>

</dependency>

<dependency>

<groupId>org.apache.deltaspike.modules</groupId>

<artifactId>*deltaspike*-*jpa*-module-*impl*</artifactId>

<version>${deltaspike.version}</version>

<scope>compile</scope>

</dependency>

<dependency>

<groupId>org.apache.deltaspike.core</groupId>

<artifactId>*deltaspike*-core-*api*</artifactId>

*<version>${deltaspike.version}</version>*

<scope>compile</scope>

</dependency>

<dependency>

<groupId>org.apache.deltaspike.core</groupId>

<artifactId>*deltaspike*-core-*impl*</artifactId>

*<version>${deltaspike.version}</version>*

<scope>compile</scope>

</dependency>

<dependency>

<groupId>org.apache.deltaspike.cdictrl</groupId>

<artifactId>*deltaspike*-*cdictrl*-weld</artifactId>

<version>${deltaspike.version}</version>

<scope>test</scope>

</dependency>

<dependency>

<groupId>org.jboss.weld.se</groupId>

<artifactId>weld-*se*-core</artifactId>

*<version>${weld.version}</version>*

<scope>test</scope>

</dependency>

Regards,
Paul Wills

Reply via email to