You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a list view for Payment that executes a polymorphic query on all subclasses.
Sort the list view by any column in Payment.
Current Behavior
Sorting results in no data being displayed in the list view.
The following test case proofs that it is not directly a problem of Jmix, but of Eclipselink (or it was used wrong):
packageio.jmix.petclinic.user;
importio.jmix.core.DataManager;
importio.jmix.core.Sort;
importio.jmix.petclinic.entity.payment.*;
importio.jmix.petclinic.test_support.AuthenticatedAsAdmin;
importjakarta.persistence.EntityManager;
importjakarta.persistence.PersistenceContext;
importjakarta.transaction.Transactional;
importorg.junit.jupiter.api.*;
importorg.junit.jupiter.api.extension.ExtendWith;
importorg.springframework.beans.factory.annotation.Autowired;
importorg.springframework.boot.test.context.SpringBootTest;
importjava.math.BigDecimal;
importjava.time.LocalDate;
importjava.util.ArrayList;
importjava.util.List;
importstaticorg.assertj.core.api.Assertions.assertThat;
@SpringBootTest@ExtendWith(AuthenticatedAsAdmin.class)
publicclassPaymentTest {
@AutowiredprivateDataManagerdataManager;
@PersistenceContextprivateEntityManagerentityManager;
privatefinalList<Object> createEntities = newArrayList<>();
@BeforeEachvoidsetUp() {
dataManager.load(Payment.class).all().list().forEach(dataManager::remove);
InsuranceProviderinsuranceProvider = dataManager.create(InsuranceProvider.class);
insuranceProvider.setName("Insurance Provider");
createEntities.add(insuranceProvider);
for (inti = 0; i < 10; i++) {
Invoiceinvoice = dataManager.create(Invoice.class);
invoice.setInvoiceDate(LocalDate.now());
invoice.setInvoiceNumber(String.valueOf(i));
createEntities.add(invoice);
CashPaymentcashPayment = dataManager.create(CashPayment.class);
cashPayment.setPaymentDate(LocalDate.now().atStartOfDay());
cashPayment.setInvoice(invoice);
cashPayment.setAmount(newBigDecimal("100.0"));
cashPayment.setAmountTendered(newBigDecimal("20.0"));
cashPayment.setChangeGiven(newBigDecimal("20.0"));
createEntities.add(cashPayment);
CreditCardPaymentcreditCardPayment = dataManager.create(CreditCardPayment.class);
creditCardPayment.setAmount(newBigDecimal("200.0"));
creditCardPayment.setPaymentDate(LocalDate.now().atStartOfDay());
creditCardPayment.setInvoice(invoice);
creditCardPayment.setCardNumber(String.valueOf(i));
creditCardPayment.setCardHolderName("Card Holder Name");
createEntities.add(creditCardPayment);
InsurancePaymentinsurancePayment = dataManager.create(InsurancePayment.class);
insurancePayment.setAmount(newBigDecimal("300.0"));
insurancePayment.setPaymentDate(LocalDate.now().atStartOfDay());
insurancePayment.setInvoice(invoice);
insurancePayment.setInsuranceProvider(insuranceProvider);
insurancePayment.setPolicyNumber(String.valueOf(i));
createEntities.add(insurancePayment);
}
dataManager.saveAll(createEntities);
}
@NestedclassEntityManagerUsage {
@Test@DisplayName("Without sorting it works - as expected")
voidtest_jmixEntityManager_query() {
// when:List<Payment> results = entityManager.createQuery("SELECT p FROM petclinic_Payment p", Payment.class)
.getResultList();
// then:assertThat(results).isNotEmpty();
}
@Test@DisplayName("With sorting it does not work - NOT as expected")
voidtest_jmixEntityManager_withSorting_query() {
// when:List<Payment> results = entityManager.createQuery("SELECT p FROM petclinic_Payment p order by p.paymentDate", Payment.class)
.getResultList();
// then:assertThat(results).isNotEmpty();
}
}
@NestedclassDelegateEntityManagerUsage {
@Test@Transactional@DisplayName("Without sorting it works - as expected")
voidtest_delegateEntityManager_query() {
// given:EntityManagerdelegate = (EntityManager) entityManager.getDelegate();
// when:List<Payment> results = delegate.createQuery("SELECT p FROM petclinic_Payment p", Payment.class)
.getResultList();
// then:assertThat(results).isNotEmpty();
}
@Transactional@Test@DisplayName("With sorting it does not work - NOT as expected")
voidtest_delegateEntityManager_withSorting_query() {
// given:EntityManagerdelegate = (EntityManager) entityManager.getDelegate();
// when:List<Payment> results = delegate.createQuery("SELECT p FROM petclinic_Payment p order by p.paymentDate", Payment.class)
.getResultList();
// then:assertThat(results).isNotEmpty();
}
}
@NestedclassDataManagerUsage {
@Test@DisplayName("Without sorting it works - as expected")
voidtest_dataManagerWithoutSort_query() {
// when:List<Payment> results = dataManager.load(Payment.class)
.all()
.list();
// then:assertThat(results).isNotEmpty();
}
@Test@DisplayName("With sorting it does not work - NOT as expected")
voidtest_dataManager_withSorting_query() {
// when:List<Payment> results = dataManager.load(Payment.class)
.all()
.sort(Sort.by("paymentDate"))
.list();
// then:assertThat(results).isNotEmpty();
}
}
@AfterEachvoidtearDown() {
createEntities.forEach(dataManager::remove);
}
}
The test fails although it should pass:
Expecting actual not to be empty
java.lang.AssertionError:
Expecting actual not to be empty
at io.jmix.petclinic.user.PaymentTest$DataManagerUsage.test_dataManager_withSorting_query(PaymentTest.java:168)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:728)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at ...
Expected Behavior
Sorting should correctly order results across all subclasses.
Environment
Jmix version: 2.4.1
Database: PostgreSQL
Bug Description
Sorting on columns in a Payment list view (polymorphic query) does not return any results.
Steps To Reproduce
Payment
hierarchy using Table-Per-Class Inheritance:Payment
that executes a polymorphic query on all subclasses.Payment
.Current Behavior
The following test case proofs that it is not directly a problem of Jmix, but of Eclipselink (or it was used wrong):
The test fails although it should pass:
Expected Behavior
Sample Project
jmix-sample-with-test-case.zip
The text was updated successfully, but these errors were encountered: