From 2f66e07c25286cf4c09316379cb2b2722e8ef226 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Fri, 9 Feb 2018 22:20:57 +1300 Subject: [PATCH] Add test for https://github.com/ebean-orm/ebean/issues/1254 --- .../org/example/EbeanSpringModuleTest.java | 13 ++++++++ src/test/java/org/example/UserService.java | 30 ++++--------------- .../java/org/example/UserServiceImpl.java | 8 +++++ 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/test/java/org/example/EbeanSpringModuleTest.java b/src/test/java/org/example/EbeanSpringModuleTest.java index a17452005..54b1485af 100644 --- a/src/test/java/org/example/EbeanSpringModuleTest.java +++ b/src/test/java/org/example/EbeanSpringModuleTest.java @@ -83,6 +83,19 @@ public class EbeanSpringModuleTest { logger.info("Found User with OID = 1"); } + @Test + public void testNonTransactional() { + userService.nonTransactional(); + logger.info("nonTransactional done"); + } + + @Test + public void testFindNonTransactional() { + logger.info("Finding User with OID = 1 ..."); + User user = userService.find(1); + logger.info("nonTransactional find " + user); + } + /** * Return the user service. */ diff --git a/src/test/java/org/example/UserService.java b/src/test/java/org/example/UserService.java index c4e7301c9..33c037a54 100644 --- a/src/test/java/org/example/UserService.java +++ b/src/test/java/org/example/UserService.java @@ -1,35 +1,17 @@ -/** - * Copyright (C) 2009 the original author or authors - * - * This file is part of Ebean. - * - * Ebean is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * Ebean is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Ebean; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - package org.example; /** * The Interface UserService. - * @since 18.05.2009 - * @author E Mc Greal */ public interface UserService { - void save(User user); + void save(User user); User find(long id); - void batchInsert(); + User findNoCurrentTransaction(long id); + + void nonTransactional(); + + void batchInsert(); } diff --git a/src/test/java/org/example/UserServiceImpl.java b/src/test/java/org/example/UserServiceImpl.java index 43448b8ed..ccd6764ea 100644 --- a/src/test/java/org/example/UserServiceImpl.java +++ b/src/test/java/org/example/UserServiceImpl.java @@ -52,6 +52,14 @@ public class UserServiceImpl implements UserService { return ebeanServer.find(User.class, id); } + public void nonTransactional() { + ebeanServer.currentTransaction(); + } + + public User findNoCurrentTransaction(long id) { + return ebeanServer.find(User.class, id); + } + @Transactional(propagation = Propagation.REQUIRED) public void batchInsert() {