DATAJPA-376 - PersistentProperty now considers JPA @Transient.

JpaPersistentPropertyImpl is now considered persistent if it carries a @javax.persistence.Transient annotation. This should allow persistence providers to safely generate additional fields and not cause trouble in the mapping framework this way.
This commit is contained in:
Oliver Gierke
2013-07-25 10:34:21 +02:00
parent 34854d2f02
commit 153999d141
2 changed files with 22 additions and 4 deletions

View File

@@ -29,6 +29,7 @@ import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Transient;
import javax.persistence.metamodel.EmbeddableType;
import javax.persistence.metamodel.ManagedType;
import javax.persistence.metamodel.Metamodel;
@@ -132,6 +133,15 @@ class JpaPersistentPropertyImpl extends AnnotationBasedPersistentProperty<JpaPer
return false;
}
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.model.AnnotationBasedPersistentProperty#isTransient()
*/
@Override
public boolean isTransient() {
return isAnnotationPresent(Transient.class) || super.isTransient();
}
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.model.AbstractPersistentProperty#createAssociation()

View File

@@ -19,6 +19,7 @@ import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import javax.persistence.OneToOne;
import javax.persistence.Transient;
import javax.persistence.metamodel.Metamodel;
import org.junit.Before;
@@ -35,8 +36,7 @@ import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class JpaPersistentPropertyImplUnitTests {
@Mock
Metamodel model;
@Mock Metamodel model;
JpaMetamodelMappingContext context;
JpaPersistentEntity<?> entity;
@@ -58,9 +58,17 @@ public class JpaPersistentPropertyImplUnitTests {
assertThat(property.isAssociation(), is(true));
}
/**
* @see DATAJPA-376
*/
@Test
public void considersJpaTransientFieldsAsTransient() {
assertThat(entity.getPersistentProperty("transientProp"), is(nullValue()));
}
static class Sample {
@OneToOne
Sample other;
@OneToOne Sample other;
@Transient String transientProp;
}
}