From 32e836971a4071f241fd87ea072c567e189cf7ac Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Thu, 29 Aug 2013 12:34:23 +0200 Subject: [PATCH] MyBatis-Spring: insert with @Transactional --- .../src/main/java/de/example/mybatis/spring/TestMain.java | 2 ++ .../de/example/mybatis/spring/service/ExampleService.java | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/TestMain.java b/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/TestMain.java index 19caac1..396fbdf 100644 --- a/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/TestMain.java +++ b/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/TestMain.java @@ -14,6 +14,8 @@ public class TestMain { final ExampleService exampleService = (ExampleService) SpringContextLocator .getInstance().getBean("exampleService"); + exampleService.insertNewAd(); + exampleService.getAdsByCriteria(); } diff --git a/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/service/ExampleService.java b/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/service/ExampleService.java index f397e61..8d868ca 100644 --- a/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/service/ExampleService.java +++ b/MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/service/ExampleService.java @@ -20,7 +20,6 @@ public class ExampleService { this.adMapper = adMapper; } - @Transactional /**There is not inserts so this is useless, anyhow this is just an example**/ public void getAdsByCriteria() { logger.info("Using criteria"); @@ -53,4 +52,17 @@ public class ExampleService { logger.info("\n"); } } + + @Transactional /** With just one table, it is useless. Anyhow this an example **/ + public void insertNewAd() { + logger.info("Insert new Ad"); + + final Ad adTest = new Ad(); + adTest.setAdMobileImage("bild.jpg"); + adTest.setCompanyCategId(200L); + adTest.setCreatedAt(new Date()); + adTest.setCompanyId(2L); + adTest.setUpdatedAt(new Date()); + this.adMapper.insert(adTest); + } } \ No newline at end of file -- 2.1.4