Using Spring boot 1.3.1
I don't understand why @RestController are Transactionnal by default. I haven't found anything saying so in the docs.
Example which pushes this fact that the method findOne() in the controller below is Transactionnal:
@RestController
@RequestMapping("/books")
public class BookController {
@RequestMapping("/{id}")
public Book findOne(@PathVariable Long id) {
Book book = this.bookDao.findOneBookById(id);
// following line
// => triggers a select author0_.id as id1_0_0_ etc... // where author0_.id=?
System.out.println(book.getAuthor().getFirstname());
return book;
}
}
The line with the System.out.println(book.getAuthor().getFirstname()); should raise a LazyInitiaizationFailure BUT here it is successful and trigger the select of an an Author. So the method findOne seems to be transactionnal. With the eclipse debugger I can be sure that it is really this line that triggers the complementary select. But Why is that method transactionnal ?
@Configuration
@ComponentScan(basePackageClasses = _Controller.class)
@Import(BusinessConfig.class)
public class WebConfig extends WebMvcConfigurerAdapter {
// ... here the conf to setup Jackson Hibernate4Module
}
@Configuration
@EnableAutoConfiguration
@EnableTransactionManagement
@EntityScan(basePackageClasses = _Model.class)
@ComponentScan(basePackageClasses = { _Dao.class })
public class BusinessConfig {
}
@SpringBootApplication
public class BookstoreStartForWebEmbedded {
public static void main(String[] args) {
SpringApplication.run(BookstoreStartForWebEmbedded.class, args);
}
}
libs :
spring-boot-starter 1.3.1.RELEASE
spring-boot-starter-test : 1.3.1.RELEASE
spring-boot-starter-valisation : 1.3.1.RELEASE
spring-boot-starter-web : 1.3.1.RELEASE
spring-boot-starter-data-jpa : 1.3.1.RELEASE
postgresql: 9.4-1206-jdbc41
querydsl-jps:3.7.0
jackson-annotations:2.6.4
jackson-datatype-hibernate4:2.6.4
any idea ?
If it is a feature, i would like to switch it off...