From 5f89cfd43075f1f8b14fecb632708a29da1c94f2 Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Thu, 6 Mar 2014 17:04:49 +0100 Subject: [PATCH] DATAJPA-472 - Verify that pagination works with entities with @IdClass. This works as expected with 3.6.10, 4.2.10, 4.3.4 but fails with 4.1.12. Added test case to verify and track the issue with Hibernate 4.1.x. Renamed test-class from DataJpa269RepositoryWithCompositeKeyTests to RepositoryWithCompositeKeyTests. Original pull request: #61. --- ...a => RepositoryWithCompositeKeyTests.java} | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) rename src/test/java/org/springframework/data/jpa/repository/{DataJpa269RepositoryWithCompositeKeyTests.java => RepositoryWithCompositeKeyTests.java} (74%) diff --git a/src/test/java/org/springframework/data/jpa/repository/DataJpa269RepositoryWithCompositeKeyTests.java b/src/test/java/org/springframework/data/jpa/repository/RepositoryWithCompositeKeyTests.java similarity index 74% rename from src/test/java/org/springframework/data/jpa/repository/DataJpa269RepositoryWithCompositeKeyTests.java rename to src/test/java/org/springframework/data/jpa/repository/RepositoryWithCompositeKeyTests.java index abea7664d..e9138a815 100644 --- a/src/test/java/org/springframework/data/jpa/repository/DataJpa269RepositoryWithCompositeKeyTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/RepositoryWithCompositeKeyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,9 +18,14 @@ package org.springframework.data.jpa.repository; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.InvalidDataAccessApiUsageException; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.domain.sample.EmbeddedIdExampleDepartment; import org.springframework.data.jpa.domain.sample.EmbeddedIdExampleEmployee; import org.springframework.data.jpa.domain.sample.EmbeddedIdExampleEmployeePK; @@ -37,13 +42,14 @@ import org.springframework.transaction.annotation.Transactional; /** * Tests some usage variants of composite keys with spring data jpa. * - * @see DATAJPA-269 * @author Thomas Darimont */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = SampleConfig.class) @Transactional -public class DataJpa269RepositoryWithCompositeKeyTests { +public class RepositoryWithCompositeKeyTests { + + @Rule public ExpectedException expectedException = ExpectedException.none(); @Autowired EmployeeRepositoryWithIdClass employeeRepositoryWithIdClass; @Autowired EmployeeRepositoryWithEmbeddedId employeeRepositoryWithEmbeddedId; @@ -99,6 +105,32 @@ public class DataJpa269RepositoryWithCompositeKeyTests { assertThat(persistedEmp, is(notNullValue())); assertThat(persistedEmp.getDepartment(), is(notNullValue())); assertThat(persistedEmp.getDepartment().getName(), is(dep.getName())); + } + /** + * @see DATAJPA-472 + */ + @Test + public void shouldSupportFindAllWithPageableAndEntityWithIdClass() throws Exception { + + if (Package.getPackage("org.hibernate.cfg").getImplementationVersion().startsWith("4.1.")) { + + // we expect this test to fail on 4.1.x - due to a bug in hibernate - remove as soon as 4.1.x fixes the issue. + expectedException.expect(InvalidDataAccessApiUsageException.class); + expectedException.expectMessage("No supertype found"); + } + + IdClassExampleDepartment dep = new IdClassExampleDepartment(); + dep.setName("TestDepartment"); + dep.setDepartmentId(-1); + + IdClassExampleEmployee emp = new IdClassExampleEmployee(); + emp.setDepartment(dep); + emp = employeeRepositoryWithIdClass.save(emp); + + Page page = employeeRepositoryWithIdClass.findAll(new PageRequest(0, 10)); + + assertThat(page, is(notNullValue())); + assertThat(page.getTotalElements(), is(1L)); } }