Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8127095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:24:09+00:00 2026-06-06T07:24:09+00:00

Essence: How can I auto-rollback my hibernate transaction in a JUnit Test run with

  • 0

Essence:

How can I auto-rollback my hibernate transaction in a JUnit Test run with JBehave?

The problem seems to be that JBehave wants the SpringAnnotatedEmbedderRunner but annotating a test as @Transactional requires the SpringJUnit4ClassRunner.

I’ve tried to find some documentation on how to implement either rollback with SpringAnnotatedEmbedderRunner or to make JBehave work using the SpringJUnit4ClassRunner but I couldn’t get either to work.

Does anyone have a (preferably simple) setup that runs JBehave storries with Spring and Hibernate and transaction auto-rollback?



Further infos about my setup so far:

Working JBehave with Spring – but not with auto-rollback:

@RunWith(SpringAnnotatedEmbedderRunner.class)
@Configure(parameterConverters = ParameterConverters.EnumConverter.class)
@UsingEmbedder(embedder = Embedder.class, generateViewAfterStories = true, ignoreFailureInStories = false, ignoreFailureInView = false)
@UsingSpring(resources = { "file:src/main/webapp/WEB-INF/test-context.xml" })
@UsingSteps
@Transactional // << won't work
@TransactionConfiguration(...) // << won't work
// both require the SpringJUnit4ClassRunner 

public class DwStoryTests extends JUnitStories {

    protected List<String> storyPaths() {

        String searchInDirectory = CodeLocations.codeLocationFromPath("src/test/resources").getFile();
        return new StoryFinder().findPaths(searchInDirectory, Arrays.asList("**/*.story"), null);
    }

}

In my test steps I can @Inject everything nicely:

@Component
@Transactional // << won't work
public class PersonServiceSteps extends AbstractSmockServerTest {

    @Inject
    private DatabaseSetupHelper databaseSetupHelper;

    @Inject
    private PersonProvider personProvider;

    @Given("a database in default state")
    public void setupDatabase() throws SecurityException {
        databaseSetupHelper.createTypes();
        databaseSetupHelper.createPermission();
    }

    @When("the service $service is called with message $message")
    public void callServiceWithMessage(String service, String message) {
        sendRequestTo("/personService", withMessage("requestPersonSave.xml")).andExpect(noFault());
    }

    @Then("there should be a new person in the database")
    public void assertNewPersonInDatabase() {
        Assert.assertEquals("Service did not save person: ", personProvider.count(), 1);
    }

(yes, the databaseSetupHelper methods are all transactional)

PersonProvider is basicly a wrapper around org.springframework.data.jpa.repository.support.SimpleJpaRepository. So there is access to the entityManager but taking control over the transactions (with begin/rollback) didn’t work, I guess because of all the @Transactionals that are done under the hood inside that helper class.

Also I read that JBehave runs in a different context?session?something? which causes loss of controll over the transaction started by the test? Pretty confusing stuff..


edit:

Editet the above rephrasing the post to reflect my current knowledge and shortening the whole thing so that the question becomes more obvious and the setup less obstrusive.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:24:12+00:00Added an answer on June 6, 2026 at 7:24 am

    I think you can skip the SpringAnnotatedEmbedderRunner and provide the necessary configuration to JBehave yourself. For example instead of

    @UsingEmbedder(embedder = Embedder.class, generateViewAfterStories = true, ignoreFailureInStories = false, ignoreFailureInView = false)
    

    you can do

    configuredEmbedder()
    .embedderControls()
    .doGenerateViewAfterStories(true)
    .doIgnoreFailureInStories(false)
    .doIgnoreFailureInView(false);
    

    Besides: why do you want to rollback the transaction? Typically you are using JBehave for acceptance tests, which run in a production-like environment. For example you first setup some data in the database, access it via Browser/Selenium and check for the results. For that to work the DB transaction has to be committed. Do you need to clean-up manually after your tests, which you can do in @AfterStories or @AfterScenario annotated methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The essence of my problem is that I can't write to a file in
I have a problem which has an solution that can be solved by iteration,
In essence what I'm trying to do is create a CSS style that can
The essence of the problem is, given a class hierarchy like this: class A
This question seems to be the essence of several others on this forum. I
I have a need for some kind of information that is in essence static.
I have a Tridion implementation that is, in essence, multi-tennent. Different interest groups use
We are putting together a platform that can supposedly load any jar file and
I have a MySQL table that's being updated very frequently. In essence, I'm trying
I've simplified the problem somewhat, but I hope I've still captured the essence of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.