use of jakarta.persistence.OneToOne in project hibernate-orm by hibernate.
the class JPAXMLOverriddenAnnotationReader method getOneToOne.
/**
* As per section 12.2 of the JPA 2.0 specification, the association
* subelements (many-to-one, one-to-many, one-to-one, many-to-many,
* element-collection) completely override the mapping for the specified
* field or property. Thus, any methods which might in some contexts merge
* with annotations must not do so in this context.
*
* @see #getElementCollection(List, XMLContext.Default)
*/
private void getOneToOne(List<Annotation> annotationList, XMLContext.Default defaults) {
Class<OneToOne> annotationType = OneToOne.class;
List<JaxbOneToOne> elements = elementsForProperty.getOneToOne();
for (JaxbOneToOne element : elements) {
AnnotationDescriptor ad = new AnnotationDescriptor(annotationType);
addTargetClass(element.getTargetEntity(), ad, "target-entity", defaults);
getFetchType(ad, element.getFetch());
getCascades(ad, element.getCascade(), defaults);
getJoinTable(annotationList, element, defaults);
buildJoinColumns(annotationList, element.getJoinColumn());
Annotation annotation = getPrimaryKeyJoinColumns(element.getPrimaryKeyJoinColumn(), defaults, false);
addIfNotNull(annotationList, annotation);
copyAttribute(ad, "optional", element.isOptional(), false);
copyAttribute(ad, "orphan-removal", element.isOrphanRemoval(), false);
copyAttribute(ad, "mapped-by", element.getMappedBy(), false);
annotationList.add(AnnotationFactory.create(ad));
getAssociationId(annotationList, element.isId());
getMapsId(annotationList, element.getMapsId());
getAccessType(annotationList, element.getAccess());
}
afterGetAssociation(annotationType, annotationList, defaults);
}
use of jakarta.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 jakarta.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 jakarta.persistence.OneToOne in project hibernate-orm by hibernate.
the class Ejb3XmlOneToOneTest method testCascadeSomeWithDefaultPersist.
@Test
public void testCascadeSomeWithDefaultPersist() throws Exception {
reader = getReader(Entity1.class, "field1", "one-to-one.orm9.xml");
assertAnnotationPresent(OneToOne.class);
OneToOne relAnno = reader.getAnnotation(OneToOne.class);
assertEquals(4, relAnno.cascade().length);
assertEquals(CascadeType.REMOVE, relAnno.cascade()[0]);
assertEquals(CascadeType.REFRESH, relAnno.cascade()[1]);
assertEquals(CascadeType.DETACH, relAnno.cascade()[2]);
assertEquals(CascadeType.PERSIST, relAnno.cascade()[3]);
}
use of jakarta.persistence.OneToOne in project jackson-datatype-hibernate by FasterXML.
the class PersistentCollectionSerializer method usesLazyLoading.
/**
* Method called to see whether given property indicates it uses lazy
* resolution of reference contained.
*/
protected boolean usesLazyLoading(BeanProperty property) {
if (property != null) {
// As per [Issue#36]
ElementCollection ec = property.getAnnotation(ElementCollection.class);
if (ec != null) {
return (ec.fetch() == FetchType.LAZY);
}
OneToMany ann1 = property.getAnnotation(OneToMany.class);
if (ann1 != null) {
return (ann1.fetch() == FetchType.LAZY);
}
OneToOne ann2 = property.getAnnotation(OneToOne.class);
if (ann2 != null) {
return (ann2.fetch() == FetchType.LAZY);
}
ManyToOne ann3 = property.getAnnotation(ManyToOne.class);
if (ann3 != null) {
return (ann3.fetch() == FetchType.LAZY);
}
ManyToMany ann4 = property.getAnnotation(ManyToMany.class);
if (ann4 != null) {
return (ann4.fetch() == FetchType.LAZY);
}
// As per [Issue#53]
return !Feature.REQUIRE_EXPLICIT_LAZY_LOADING_MARKER.enabledIn(_features);
}
return false;
}
Aggregations