Search in sources :

Example 11 with OneToOne

use of jakarta.persistence.OneToOne in project hibernate-orm by hibernate.

the class Ejb3XmlOneToOneTest method testCascadeAll.

@Test
public void testCascadeAll() throws Exception {
    reader = getReader(Entity1.class, "field1", "one-to-one.orm8.xml");
    assertAnnotationPresent(OneToOne.class);
    OneToOne relAnno = reader.getAnnotation(OneToOne.class);
    assertEquals(1, relAnno.cascade().length);
    assertEquals(CascadeType.ALL, relAnno.cascade()[0]);
}
Also used : OneToOne(jakarta.persistence.OneToOne) Test(org.junit.Test)

Example 12 with OneToOne

use of jakarta.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());
}
Also used : OneToOne(jakarta.persistence.OneToOne) Test(org.junit.Test)

Example 13 with OneToOne

use of jakarta.persistence.OneToOne in project eclipselink by eclipse-ee4j.

the class AbstractFieldMapping method getMemberType.

@Override
protected Class<?> getMemberType() {
    Field field = getMember();
    // One to One
    OneToOne oneToOne = field.getAnnotation(OneToOne.class);
    if (oneToOne != null) {
        Class<?> targetEntity = oneToOne.targetEntity();
        if (targetEntity != void.class) {
            return targetEntity;
        }
    }
    // Many to One
    ManyToOne manyToOne = field.getAnnotation(ManyToOne.class);
    if (manyToOne != null) {
        Class<?> targetEntity = manyToOne.targetEntity();
        if (targetEntity != void.class) {
            return targetEntity;
        }
    }
    // Many to Many
    ManyToMany manyToMany = field.getAnnotation(ManyToMany.class);
    if (manyToMany != null) {
        Class<?> targetEntity = manyToMany.targetEntity();
        if (targetEntity != void.class) {
            return targetEntity;
        }
    }
    // One to Many
    OneToMany oneToMany = field.getAnnotation(OneToMany.class);
    if (oneToMany != null) {
        Class<?> targetEntity = oneToMany.targetEntity();
        if (targetEntity != void.class) {
            return targetEntity;
        }
    }
    return field.getType();
}
Also used : Field(java.lang.reflect.Field) OneToOne(jakarta.persistence.OneToOne) ManyToMany(jakarta.persistence.ManyToMany) OneToMany(jakarta.persistence.OneToMany) ManyToOne(jakarta.persistence.ManyToOne)

Example 14 with OneToOne

use of jakarta.persistence.OneToOne in project eclipselink by eclipse-ee4j.

the class AbstractMethodMapping method getMemberType.

@Override
protected Class<?> getMemberType() {
    Method method = getMember();
    Class<?> type = method.getReturnType();
    if (type == Void.class) {
        return method.getParameterTypes()[0];
    } else {
        // One to One
        OneToOne oneToOne = method.getAnnotation(OneToOne.class);
        if (oneToOne != null) {
            Class<?> targetEntity = oneToOne.targetEntity();
            if (targetEntity != void.class) {
                return targetEntity;
            }
        }
        // Many to One
        ManyToOne manyToOne = method.getAnnotation(ManyToOne.class);
        if (manyToOne != null) {
            Class<?> targetEntity = manyToOne.targetEntity();
            if (targetEntity != void.class) {
                return targetEntity;
            }
        }
        // Many to Many
        ManyToMany manyToMany = method.getAnnotation(ManyToMany.class);
        if (manyToMany != null) {
            Class<?> targetEntity = manyToMany.targetEntity();
            if (targetEntity != void.class) {
                return targetEntity;
            }
        }
        // One to Many
        OneToMany oneToMany = method.getAnnotation(OneToMany.class);
        if (oneToMany != null) {
            Class<?> targetEntity = oneToMany.targetEntity();
            if (targetEntity != void.class) {
                return targetEntity;
            }
        }
        return type;
    }
}
Also used : OneToOne(jakarta.persistence.OneToOne) ManyToMany(jakarta.persistence.ManyToMany) Method(java.lang.reflect.Method) OneToMany(jakarta.persistence.OneToMany) ManyToOne(jakarta.persistence.ManyToOne)

Aggregations

OneToOne (jakarta.persistence.OneToOne)14 ManyToOne (jakarta.persistence.ManyToOne)6 Test (org.junit.Test)5 ManyToMany (jakarta.persistence.ManyToMany)3 OneToMany (jakarta.persistence.OneToMany)3 AnnotationException (org.hibernate.AnnotationException)3 JoinTable (jakarta.persistence.JoinTable)2 AssertionFailure (org.hibernate.AssertionFailure)2 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)2 JaxbOneToOne (org.hibernate.boot.jaxb.mapping.spi.JaxbOneToOne)2 CascadeType (jakarta.persistence.CascadeType)1 Column (jakarta.persistence.Column)1 DiscriminatorColumn (jakarta.persistence.DiscriminatorColumn)1 ElementCollection (jakarta.persistence.ElementCollection)1 FetchType (jakarta.persistence.FetchType)1 JoinColumn (jakarta.persistence.JoinColumn)1 JoinColumns (jakarta.persistence.JoinColumns)1 MapKeyColumn (jakarta.persistence.MapKeyColumn)1 MapKeyJoinColumn (jakarta.persistence.MapKeyJoinColumn)1 MapKeyJoinColumns (jakarta.persistence.MapKeyJoinColumns)1