diff --git a/src/main/java/org/springframework/data/jpa/mapping/JpaPersistentPropertyImpl.java b/src/main/java/org/springframework/data/jpa/mapping/JpaPersistentPropertyImpl.java index 345dd8a54..a9dc06c89 100644 --- a/src/main/java/org/springframework/data/jpa/mapping/JpaPersistentPropertyImpl.java +++ b/src/main/java/org/springframework/data/jpa/mapping/JpaPersistentPropertyImpl.java @@ -28,6 +28,7 @@ import javax.persistence.Id; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import javax.persistence.OneToOne; import javax.persistence.metamodel.EmbeddableType; import javax.persistence.metamodel.ManagedType; import javax.persistence.metamodel.Metamodel; @@ -53,6 +54,7 @@ class JpaPersistentPropertyImpl extends AnnotationBasedPersistentProperty> annotations = new HashSet>(); annotations.add(OneToMany.class); + annotations.add(OneToOne.class); annotations.add(ManyToMany.class); annotations.add(ManyToOne.class); diff --git a/src/test/java/org/springframework/data/jpa/mapping/JpaPersistentPropertyImplUnitTests.java b/src/test/java/org/springframework/data/jpa/mapping/JpaPersistentPropertyImplUnitTests.java new file mode 100644 index 000000000..e9f459569 --- /dev/null +++ b/src/test/java/org/springframework/data/jpa/mapping/JpaPersistentPropertyImplUnitTests.java @@ -0,0 +1,66 @@ +/* + * 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.mapping; + +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assert.*; + +import javax.persistence.OneToOne; +import javax.persistence.metamodel.Metamodel; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +/** + * Unit tests for {@link JpaPersistentPropertyImpl}. + * + * @author Oliver Gierke + */ +@RunWith(MockitoJUnitRunner.class) +public class JpaPersistentPropertyImplUnitTests { + + @Mock + Metamodel model; + + JpaMetamodelMappingContext context; + JpaPersistentEntity entity; + + @Before + public void setUp() { + + context = new JpaMetamodelMappingContext(model); + entity = context.getPersistentEntity(Sample.class); + } + + /** + * @see DATAJPA-284 + */ + @Test + public void considersOneToOneMappedPropertyAnAssociation() { + + JpaPersistentProperty property = entity.getPersistentProperty("other"); + assertThat(property.isAssociation(), is(true)); + } + + static class Sample { + + @OneToOne + Sample other; + } +}