use of javax.persistence.OneToOne in project hibernate-orm by hibernate.
the class Ejb3XmlOneToOneTest method testCascadeAllPlusMore.
/**
* Make sure that it doesn't break the handler when {@link CascadeType#ALL}
* is specified in addition to a default cascade-persist or individual
* cascade settings.
*/
@Test
public void testCascadeAllPlusMore() throws Exception {
reader = getReader(Entity1.class, "field1", "one-to-one.orm10.xml");
assertAnnotationPresent(OneToOne.class);
OneToOne relAnno = reader.getAnnotation(OneToOne.class);
assertEquals(6, relAnno.cascade().length);
assertEquals(CascadeType.ALL, relAnno.cascade()[0]);
assertEquals(CascadeType.PERSIST, relAnno.cascade()[1]);
assertEquals(CascadeType.MERGE, relAnno.cascade()[2]);
assertEquals(CascadeType.REMOVE, relAnno.cascade()[3]);
assertEquals(CascadeType.REFRESH, relAnno.cascade()[4]);
assertEquals(CascadeType.DETACH, relAnno.cascade()[5]);
}
use of javax.persistence.OneToOne in project hibernate-orm by hibernate.
the class Ejb3XmlOneToOneTest method testNoChildren.
@Test
public void testNoChildren() throws Exception {
reader = getReader(Entity1.class, "field1", "one-to-one.orm1.xml");
assertAnnotationPresent(OneToOne.class);
assertAnnotationNotPresent(MapsId.class);
assertAnnotationNotPresent(Id.class);
assertAnnotationNotPresent(PrimaryKeyJoinColumn.class);
assertAnnotationNotPresent(PrimaryKeyJoinColumns.class);
assertAnnotationNotPresent(JoinColumns.class);
assertAnnotationNotPresent(JoinColumn.class);
assertAnnotationNotPresent(JoinTable.class);
assertAnnotationNotPresent(Access.class);
OneToOne relAnno = reader.getAnnotation(OneToOne.class);
assertEquals(0, relAnno.cascade().length);
assertEquals(FetchType.EAGER, relAnno.fetch());
assertEquals("", relAnno.mappedBy());
assertTrue(relAnno.optional());
assertFalse(relAnno.orphanRemoval());
assertEquals(void.class, relAnno.targetEntity());
}
use of javax.persistence.OneToOne in project hibernate-orm by hibernate.
the class Ejb3XmlOneToOneTest method testAllAttributes.
@Test
public void testAllAttributes() throws Exception {
reader = getReader(Entity1.class, "field1", "one-to-one.orm11.xml");
assertAnnotationPresent(OneToOne.class);
assertAnnotationPresent(MapsId.class);
assertAnnotationPresent(Id.class);
assertAnnotationNotPresent(PrimaryKeyJoinColumn.class);
assertAnnotationNotPresent(PrimaryKeyJoinColumns.class);
assertAnnotationNotPresent(JoinColumns.class);
assertAnnotationNotPresent(JoinColumn.class);
assertAnnotationNotPresent(JoinTable.class);
assertAnnotationPresent(Access.class);
OneToOne relAnno = reader.getAnnotation(OneToOne.class);
assertEquals(0, relAnno.cascade().length);
assertEquals(FetchType.LAZY, relAnno.fetch());
assertEquals("field2", relAnno.mappedBy());
assertFalse(relAnno.optional());
assertTrue(relAnno.orphanRemoval());
assertEquals(Entity3.class, relAnno.targetEntity());
assertEquals(AccessType.PROPERTY, reader.getAnnotation(Access.class).value());
assertEquals("field3", reader.getAnnotation(MapsId.class).value());
}
use of javax.persistence.OneToOne in project hibernate-orm by hibernate.
the class ToOneBinder method getTargetEntityClass.
private static Class<?> getTargetEntityClass(XProperty property) {
final ManyToOne mTo = property.getAnnotation(ManyToOne.class);
if (mTo != null) {
return mTo.targetEntity();
}
final OneToOne oTo = property.getAnnotation(OneToOne.class);
if (oTo != null) {
return oTo.targetEntity();
}
throw new AssertionFailure("Unexpected discovery of a targetEntity: " + property.getName());
}
use of javax.persistence.OneToOne in project hibernate-orm by hibernate.
the class AnnotationBinder method defineFetchingStrategy.
protected static void defineFetchingStrategy(ToOne toOne, XProperty property) {
LazyToOne lazy = property.getAnnotation(LazyToOne.class);
Fetch fetch = property.getAnnotation(Fetch.class);
ManyToOne manyToOne = property.getAnnotation(ManyToOne.class);
OneToOne oneToOne = property.getAnnotation(OneToOne.class);
FetchType fetchType;
if (manyToOne != null) {
fetchType = manyToOne.fetch();
} else if (oneToOne != null) {
fetchType = oneToOne.fetch();
} else {
throw new AssertionFailure("Define fetch strategy on a property not annotated with @OneToMany nor @OneToOne");
}
if (lazy != null) {
toOne.setLazy(!(lazy.value() == LazyToOneOption.FALSE));
toOne.setUnwrapProxy((lazy.value() == LazyToOneOption.NO_PROXY));
} else {
toOne.setLazy(fetchType == FetchType.LAZY);
toOne.setUnwrapProxy(false);
}
if (fetch != null) {
if (fetch.value() == org.hibernate.annotations.FetchMode.JOIN) {
toOne.setFetchMode(FetchMode.JOIN);
toOne.setLazy(false);
toOne.setUnwrapProxy(false);
} else if (fetch.value() == org.hibernate.annotations.FetchMode.SELECT) {
toOne.setFetchMode(FetchMode.SELECT);
} else if (fetch.value() == org.hibernate.annotations.FetchMode.SUBSELECT) {
throw new AnnotationException("Use of FetchMode.SUBSELECT not allowed on ToOne associations");
} else {
throw new AssertionFailure("Unknown FetchMode: " + fetch.value());
}
} else {
toOne.setFetchMode(getFetchMode(fetchType));
}
}
Aggregations