P
P
P_Alexander2018-06-08 19:21:09
Java
P_Alexander, 2018-06-08 19:21:09

Why is @Transactional not written to the database when using the @Transactional annotation?

Hello, I understand that with such a question, you can immediately send to read the tutorials, but I'm reading and studying, but I haven't found an answer yet, I'll be glad for any help.
The usual test, when using the annotation, it is not written to the database, why is it written without the annotation (specifically in my example)?

@Test
    @Transactional
    public void writingStartValuesOnDBTest() {
        logger.error("HELLO");
        Role role = new Role();
        role.setNameRole("admin");

        User user = new User("Alex0", "Login",
                "[email protected]", "111111111", LocalDate.now(), role);
        role.getUsers().add(user);
        roleService.saveRole(role);
    }

stacktrace
2018-06-08 18:57:15,857 main ERROR Loggers cannot be configured without a name: arg[2](String)
2018-06-08 18:57:15,864 main ERROR Unable to invoke factory method in class class org.apache.logging.log4j.core.config.LoggerConfig for element Logger. org.apache.logging.log4j.core.config.ConfigurationException: Arguments given for element Logger are invalid
  at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.generateParameters(PluginBuilder.java:270)
  at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:131)
  at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:952)
  at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:892)
  at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:884)
  at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:508)
  at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:232)
  at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:244)
  at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
  at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:617)
  at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
  at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
  at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:152)
  at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
  at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
  at org.apache.commons.logging.LogFactory$Log4jLog.<clinit>(LogFactory.java:199)
  at org.apache.commons.logging.LogFactory$Log4jDelegate.createLog(LogFactory.java:166)
  at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:109)
  at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:99)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<clinit>(SpringJUnit4ClassRunner.java:99)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
  at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
  at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
  at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
  at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
  at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
  at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:36)
  at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
  at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
  at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
  at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

2018-06-08 18:57:15,880 main ERROR Null object returned for Logger in Loggers.
Hibernate: select nextval ('pc_seq_role')
Hibernate: select nextval ('pc_seq_user')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
al_gon, 2018-06-08
@P_Alexander

If what you showed is all, then you are missing entityManager.flush();
Well, about Spring JPA tests and transactions , it’s very well chewed here.
PS: StackTrace is from another opera, I guess.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question