DATAJPA-484 - Improved registration of JpaMetamodelMappingContext.
Instead of creating an individual instance of JpaMetamodelMappingContext per repository we now register a unique instance with access to the metamodel of the EntityManager the repositories use under "jpaMappingContext". Weakened the contract in JpaPersistentEntityImpl to allow multiple @Id properties (in case @IdClass is used). The mapping context now also allows looking up of embeddable types as they're considered entities in the context of Spring Data mapping metadata.
This commit is contained in:
@@ -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,6 +18,8 @@ package org.springframework.data.jpa.mapping;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Transient;
|
||||
import javax.persistence.metamodel.Metamodel;
|
||||
@@ -66,9 +68,44 @@ public class JpaPersistentPropertyImplUnitTests {
|
||||
assertThat(entity.getPersistentProperty("transientProp"), is(nullValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-484
|
||||
*/
|
||||
@Test
|
||||
public void considersEmbeddableAnEntity() {
|
||||
assertThat(context.getPersistentEntity(SampleEmbeddable.class), is(notNullValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-484
|
||||
*/
|
||||
@Test
|
||||
public void considersEmbeddablePropertyAnAssociation() {
|
||||
assertThat(entity.getPersistentProperty("embeddable").isAssociation(), is(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-484
|
||||
*/
|
||||
@Test
|
||||
public void considersEmbeddedPropertyAnAssociation() {
|
||||
assertThat(entity.getPersistentProperty("embedded").isAssociation(), is(true));
|
||||
}
|
||||
|
||||
static class Sample {
|
||||
|
||||
@OneToOne Sample other;
|
||||
@Transient String transientProp;
|
||||
SampleEmbeddable embeddable;
|
||||
@Embedded SampleEmbedded embedded;
|
||||
}
|
||||
|
||||
@Embeddable
|
||||
static class SampleEmbeddable {
|
||||
|
||||
}
|
||||
|
||||
static class SampleEmbedded {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2013 the original author or authors.
|
||||
* Copyright 2008-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.
|
||||
@@ -20,6 +20,7 @@ import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.jpa.mapping.JpaMetamodelMappingContext;
|
||||
import org.springframework.data.jpa.repository.sample.AuditableUserRepository;
|
||||
import org.springframework.data.jpa.repository.sample.RoleRepository;
|
||||
import org.springframework.data.jpa.repository.sample.UserRepository;
|
||||
@@ -33,14 +34,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public abstract class AbstractRepositoryConfigTests {
|
||||
|
||||
@Autowired(required = false)
|
||||
UserRepository userRepository;
|
||||
@Autowired(required = false) UserRepository userRepository;
|
||||
@Autowired(required = false) RoleRepository roleRepository;
|
||||
@Autowired(required = false) AuditableUserRepository auditableUserRepository;
|
||||
|
||||
@Autowired(required = false)
|
||||
RoleRepository roleRepository;
|
||||
|
||||
@Autowired(required = false)
|
||||
AuditableUserRepository auditableUserRepository;
|
||||
@Autowired JpaMetamodelMappingContext mappingContext;
|
||||
|
||||
/**
|
||||
* Asserts that context creation detects 3 repository beans.
|
||||
@@ -53,6 +51,9 @@ public abstract class AbstractRepositoryConfigTests {
|
||||
assertNotNull(auditableUserRepository);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-330
|
||||
*/
|
||||
@Test
|
||||
public void repositoriesHaveExceptionTranslationApplied() {
|
||||
|
||||
@@ -60,4 +61,12 @@ public abstract class AbstractRepositoryConfigTests {
|
||||
JpaRepositoriesRegistrarIntegrationTests.assertExceptionTranslationActive(roleRepository);
|
||||
JpaRepositoriesRegistrarIntegrationTests.assertExceptionTranslationActive(auditableUserRepository);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-???
|
||||
*/
|
||||
@Test
|
||||
public void exposesJpaMappingContext() {
|
||||
assertNotNull(mappingContext);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user