diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fb1b54d2..b76281fae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Fix for `Document.getFields()` not returning iterable fields - Fix for failing tests on systems with non-ENGLISH locale #994 +- Fix for NPE in `DefaultTransactionalRepository` #1032 ## Release 4.3.0 - Jul 1, 2024 diff --git a/nitrite/src/main/java/org/dizitart/no2/transaction/DefaultTransactionalRepository.java b/nitrite/src/main/java/org/dizitart/no2/transaction/DefaultTransactionalRepository.java index 481282f96..6b177bf5b 100644 --- a/nitrite/src/main/java/org/dizitart/no2/transaction/DefaultTransactionalRepository.java +++ b/nitrite/src/main/java/org/dizitart/no2/transaction/DefaultTransactionalRepository.java @@ -153,7 +153,7 @@ public void clear() { @Override public Cursor find(Filter filter, FindOptions findOptions) { - return operations.find(filter, findOptions, type); + return operations.find(filter, findOptions, getType()); } @Override diff --git a/nitrite/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java b/nitrite/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java index 7d3c1ff00..65faf8259 100644 --- a/nitrite/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java +++ b/nitrite/src/test/java/org/dizitart/no2/integration/transaction/TransactionRepositoryTest.java @@ -20,19 +20,26 @@ import com.github.javafaker.Faker; import lombok.extern.slf4j.Slf4j; import org.dizitart.no2.collection.Document; +import org.dizitart.no2.collection.FindOptions; import org.dizitart.no2.collection.NitriteCollection; import org.dizitart.no2.common.meta.Attributes; import org.dizitart.no2.exceptions.NitriteIOException; import org.dizitart.no2.exceptions.TransactionException; import org.dizitart.no2.index.IndexType; import org.dizitart.no2.integration.repository.BaseObjectRepositoryTest; -import org.dizitart.no2.repository.ObjectRepository; import org.dizitart.no2.integration.repository.data.SubEmployee; +import org.dizitart.no2.integration.repository.decorator.Manufacturer; +import org.dizitart.no2.integration.repository.decorator.ManufacturerDecorator; +import org.dizitart.no2.repository.Cursor; +import org.dizitart.no2.repository.ObjectRepository; import org.dizitart.no2.transaction.Session; import org.dizitart.no2.transaction.Transaction; import org.junit.Test; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -824,4 +831,28 @@ public void testFailureOnClosedTransaction() { fail(); } } + + @Test + public void testWithEntityDecorator() { + ObjectRepository repo = db.getRepository(new ManufacturerDecorator()); + try (Session session = db.createSession()) { + try (Transaction transaction = session.beginTransaction()) { + ObjectRepository txRepo = transaction.getRepository(new ManufacturerDecorator()); + Manufacturer manufacturer = new Manufacturer(); + manufacturer.setName("John"); + manufacturer.setAddress("1234"); + manufacturer.setUniqueId(1); + txRepo.insert(manufacturer); + + Cursor cursor = txRepo.find(where("name").eq("John"), FindOptions.limitBy(1)); + for (Manufacturer item : cursor) { + assertEquals(item.getName(), "John"); + } + + transaction.commit(); + } + } + Cursor cursor = repo.find(where("name").eq("John"), FindOptions.limitBy(1)); + assertEquals(cursor.size(), 1); + } }