DATAJPA-284 - Added @OneToOne as annotation to be considered an association.

This commit is contained in:
Oliver Gierke
2013-01-16 17:48:48 +01:00
parent a7e5784406
commit 02239859bb
2 changed files with 68 additions and 0 deletions

View File

@@ -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<JpaPer
Set<Class<? extends Annotation>> annotations = new HashSet<Class<? extends Annotation>>();
annotations.add(OneToMany.class);
annotations.add(OneToOne.class);
annotations.add(ManyToMany.class);
annotations.add(ManyToOne.class);

View File

@@ -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;
}
}