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.
This commit is contained in:
Thomas Darimont
2014-03-06 17:04:49 +01:00
committed by Oliver Gierke
parent ee4c498134
commit 5f89cfd430

View File

@@ -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<IdClassExampleEmployee> page = employeeRepositoryWithIdClass.findAll(new PageRequest(0, 10));
assertThat(page, is(notNullValue()));
assertThat(page.getTotalElements(), is(1L));
}
}