Simplified example:
@Entity
public class Foo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String bar;
// getters + setters
}
public interface FooRepository extends CrudRepository<Foo, Integer> {
}
@Service
public class FooService {
private final FooRepository repository;
public FooService(FooRepository repository) {
this.repository = repository;
}
public Foo save(Foo foo) {
return repository.save(foo);
}
}
Calling fooService.save(myNewFoo)
from a controller works, while I would have expected it to fail (if I understand transactions correctly), as no method has been annotated with @Transactional
(and I actually would like it to fail). Any idea why this behavior? Who's creating a transaction behing the scene, and how to avoid this?
Additional details:
- Java 9
- MySQL connector 6.0.6
- Hibernate 5.2.12
- Spring Boot 2.0.0.M7
- Spring Data JPA 2.0.2.RELEASE