From a3143b1cf662abe0f600a79d351b4e80b97fcfc6 Mon Sep 17 00:00:00 2001 From: Robin Bygrave Date: Thu, 22 Sep 2016 21:25:22 +1200 Subject: [PATCH] #822 - EbeanServer.getBeanId(entity) does not trigger jdbc batch flush - when bean inserted with jdbc batch mode --- .../server/deploy/BeanDescriptor.java | 2 +- .../TestBatchSaveWithGetBeanId.java | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/avaje/tests/batchinsert/TestBatchSaveWithGetBeanId.java diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptor.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptor.java index b9c5126dc..fca0972de 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptor.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptor.java @@ -1814,7 +1814,7 @@ public class BeanDescriptor implements MetaBeanInfo, BeanType { * properties that make up the unique id. */ public Object getId(EntityBean bean) { - return (idProperty == null) ? null : idProperty.getValue(bean); + return (idProperty == null) ? null : idProperty.getValueIntercept(bean); } @Override diff --git a/src/test/java/com/avaje/tests/batchinsert/TestBatchSaveWithGetBeanId.java b/src/test/java/com/avaje/tests/batchinsert/TestBatchSaveWithGetBeanId.java new file mode 100644 index 000000000..7ffc0dac1 --- /dev/null +++ b/src/test/java/com/avaje/tests/batchinsert/TestBatchSaveWithGetBeanId.java @@ -0,0 +1,34 @@ +package com.avaje.tests.batchinsert; + +import com.avaje.ebean.BaseTestCase; +import com.avaje.ebean.Ebean; +import com.avaje.ebean.EbeanServer; +import com.avaje.ebean.annotation.Transactional; +import com.avaje.tests.model.basic.Customer; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +public class TestBatchSaveWithGetBeanId extends BaseTestCase { + + /** + * Making this transaction with batchSize means that the insert + * below does not occur immediately ... and the getBeanId() + * should invoke the flush (and hence trigger the insert). + */ + @Transactional(batchSize = 10) + @Test + public void test() { + + EbeanServer server = Ebean.getDefaultServer(); + Customer model = new Customer(); + model.setName("foo"); + + server.insert(model); + + // should invoke a flush which then means the + // insert occurs and the bean has an Id value + Object beanId = server.getBeanId(model); + assertNotNull(beanId); + } +}