MyBatis-Spring: insert with @Transactional
authorGustavo Martin Morcuende <gustavo@supergusarapo.(none)>
Thu, 29 Aug 2013 10:34:23 +0000 (12:34 +0200)
committerGustavo Martin Morcuende <gustavo@supergusarapo.(none)>
Thu, 29 Aug 2013 10:34:23 +0000 (12:34 +0200)
MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/TestMain.java
MyBatis/MyBatis-Spring/src/main/java/de/example/mybatis/spring/service/ExampleService.java

index 19caac1..396fbdf 100644 (file)
@@ -14,6 +14,8 @@ public class TestMain {
         final ExampleService exampleService = (ExampleService) SpringContextLocator
                 .getInstance().getBean("exampleService");
 
+        exampleService.insertNewAd();
+
         exampleService.getAdsByCriteria();
     }
 
index f397e61..8d868ca 100644 (file)
@@ -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