DATAJPA-266 - Fixed SimpleJpaRepository.exists(…) for composite ids.
We now build a correct count query for entities that use a compound key mapped using @IdClass. Added integration tests for EclipseLink and OpenJPA to run the basic tests of SimpleJpaRepository against different persistence providers. Ignored failing test against OpenJPA.
This commit is contained in:
committed by
Oliver Gierke
parent
943be87908
commit
562dc19b8c
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.support;
|
||||
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Integration tests to execute {@link JpaRepositoryTests} against EclipseLink.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@ContextConfiguration("classpath:eclipselink.xml")
|
||||
public class EclipseLinkJpaRepositoryTests extends JpaRepositoryTests {
|
||||
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityManager;
|
||||
@@ -93,5 +94,17 @@ public class JpaEntityInformationSupportUnitTests {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Iterable<String> getIdAttributeNames() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
public boolean hasCompositeId() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object getCompositeIdAttributeValue(Serializable id, String idAttribute) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2012 the original author or authors.
|
||||
* Copyright 2008-2013 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.
|
||||
@@ -74,7 +74,7 @@ public class JpaRepositoryTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* DATAJPA-50
|
||||
* @see DATAJPA-50
|
||||
*/
|
||||
@Test
|
||||
public void executesCrudOperationsForEntityWithIdClass() {
|
||||
@@ -90,6 +90,20 @@ public class JpaRepositoryTests {
|
||||
assertThat(idClassRepository.findOne(id), is(entity));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-266
|
||||
*/
|
||||
@Test
|
||||
public void testExistsForDomainObjectsWithCompositeKeys() throws Exception {
|
||||
|
||||
SampleWithIdClass s1 = idClassRepository.save(new SampleWithIdClass(1L, 1L));
|
||||
SampleWithIdClass s2 = idClassRepository.save(new SampleWithIdClass(2L, 2L));
|
||||
|
||||
assertThat(idClassRepository.exists(s1.getId()), is(true));
|
||||
assertThat(idClassRepository.exists(s2.getId()), is(true));
|
||||
assertThat(idClassRepository.exists(new SampleWithIdClassPK(1L, 2L)), is(false));
|
||||
}
|
||||
|
||||
private static interface SampleEntityRepository extends JpaRepository<SampleEntity, SampleEntityPK> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.support;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* Integration tests to execute {@link JpaRepositoryTests} against OpenJpa.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@ContextConfiguration("classpath:openjpa.xml")
|
||||
public class OpenJpaJpaRepositoryTests extends JpaRepositoryTests {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.jpa.repository.support.JpaRepositoryTests#testCrudOperationsForCompoundKeyEntity()
|
||||
*/
|
||||
@Override
|
||||
@Ignore
|
||||
public void testCrudOperationsForCompoundKeyEntity() throws Exception {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user