From: Gustavo Martin Morcuende Date: Thu, 29 Aug 2013 10:34:23 +0000 (+0200) Subject: MyBatis-Spring: insert with @Transactional X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=32e836971a4071f241fd87ea072c567e189cf7ac;p=JavaForFun MyBatis-Spring: insert with @Transactional --- 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