Search in sources :

Example 6 with AttributeOverrides

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

the class Ejb3XmlOneToManyTest method testMultipleMapKeyAttributeOverrides.

@Test
public void testMultipleMapKeyAttributeOverrides() throws Exception {
    reader = getReader(Entity3.class, "field1", "one-to-many.orm11.xml");
    assertAnnotationPresent(OneToMany.class);
    assertAnnotationNotPresent(MapKey.class);
    assertAnnotationNotPresent(MapKeyClass.class);
    assertAnnotationNotPresent(MapKeyTemporal.class);
    assertAnnotationNotPresent(MapKeyEnumerated.class);
    assertAnnotationNotPresent(MapKeyColumn.class);
    assertAnnotationNotPresent(MapKeyJoinColumns.class);
    assertAnnotationNotPresent(MapKeyJoinColumn.class);
    assertAnnotationNotPresent(AttributeOverride.class);
    assertAnnotationPresent(AttributeOverrides.class);
    AttributeOverrides overridesAnno = reader.getAnnotation(AttributeOverrides.class);
    AttributeOverride[] overrides = overridesAnno.value();
    assertEquals(2, overrides.length);
    assertEquals("field1", overrides[0].name());
    assertEquals("", overrides[0].column().name());
    assertFalse(overrides[0].column().unique());
    assertTrue(overrides[0].column().nullable());
    assertTrue(overrides[0].column().insertable());
    assertTrue(overrides[0].column().updatable());
    assertEquals("", overrides[0].column().columnDefinition());
    assertEquals("", overrides[0].column().table());
    assertEquals(255, overrides[0].column().length());
    assertEquals(0, overrides[0].column().precision());
    assertEquals(0, overrides[0].column().scale());
    assertEquals("field2", overrides[1].name());
    assertEquals("col1", overrides[1].column().name());
    assertTrue(overrides[1].column().unique());
    assertFalse(overrides[1].column().nullable());
    assertFalse(overrides[1].column().insertable());
    assertFalse(overrides[1].column().updatable());
    assertEquals("int", overrides[1].column().columnDefinition());
    assertEquals("table1", overrides[1].column().table());
    assertEquals(50, overrides[1].column().length());
    assertEquals(2, overrides[1].column().precision());
    assertEquals(1, overrides[1].column().scale());
}
Also used : AttributeOverrides(jakarta.persistence.AttributeOverrides) AttributeOverride(jakarta.persistence.AttributeOverride) Test(org.junit.Test)

Example 7 with AttributeOverrides

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

the class Ejb3XmlElementCollectionTest method testMultipleAttributeOverrides.

@Test
public void testMultipleAttributeOverrides() throws Exception {
    reader = getReader(Entity3.class, "field1", "element-collection.orm22.xml");
    assertAnnotationPresent(ElementCollection.class);
    assertAnnotationNotPresent(AttributeOverride.class);
    assertAnnotationPresent(AttributeOverrides.class);
    AttributeOverrides overridesAnno = reader.getAnnotation(AttributeOverrides.class);
    AttributeOverride[] overrides = overridesAnno.value();
    assertEquals(2, overrides.length);
    assertEquals("field1", overrides[0].name());
    assertEquals("", overrides[0].column().name());
    assertFalse(overrides[0].column().unique());
    assertTrue(overrides[0].column().nullable());
    assertTrue(overrides[0].column().insertable());
    assertTrue(overrides[0].column().updatable());
    assertEquals("", overrides[0].column().columnDefinition());
    assertEquals("", overrides[0].column().table());
    assertEquals(255, overrides[0].column().length());
    assertEquals(0, overrides[0].column().precision());
    assertEquals(0, overrides[0].column().scale());
    assertEquals("field2", overrides[1].name());
    assertEquals("col1", overrides[1].column().name());
    assertTrue(overrides[1].column().unique());
    assertFalse(overrides[1].column().nullable());
    assertFalse(overrides[1].column().insertable());
    assertFalse(overrides[1].column().updatable());
    assertEquals("int", overrides[1].column().columnDefinition());
    assertEquals("table1", overrides[1].column().table());
    assertEquals(50, overrides[1].column().length());
    assertEquals(2, overrides[1].column().precision());
    assertEquals(1, overrides[1].column().scale());
}
Also used : AttributeOverrides(jakarta.persistence.AttributeOverrides) AttributeOverride(jakarta.persistence.AttributeOverride) Test(org.junit.Test)

Example 8 with AttributeOverrides

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

the class Ejb3XmlElementCollectionTest method testSingleAttributeOverride.

/**
 * When there's a single attribute override, we still wrap it with an
 * AttributeOverrides annotation.
 */
@Test
public void testSingleAttributeOverride() throws Exception {
    reader = getReader(Entity3.class, "field1", "element-collection.orm21.xml");
    assertAnnotationPresent(ElementCollection.class);
    assertAnnotationNotPresent(AttributeOverride.class);
    assertAnnotationPresent(AttributeOverrides.class);
    AttributeOverrides overridesAnno = reader.getAnnotation(AttributeOverrides.class);
    AttributeOverride[] overrides = overridesAnno.value();
    assertEquals(1, overrides.length);
    assertEquals("field1", overrides[0].name());
    assertEquals("col1", overrides[0].column().name());
}
Also used : AttributeOverrides(jakarta.persistence.AttributeOverrides) AttributeOverride(jakarta.persistence.AttributeOverride) Test(org.junit.Test)

Example 9 with AttributeOverrides

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

the class Ejb3XmlManyToManyTest method testMultipleMapKeyAttributeOverrides.

@Test
public void testMultipleMapKeyAttributeOverrides() throws Exception {
    reader = getReader(Entity3.class, "field1", "many-to-many.orm11.xml");
    assertAnnotationPresent(ManyToMany.class);
    assertAnnotationNotPresent(MapKey.class);
    assertAnnotationNotPresent(MapKeyClass.class);
    assertAnnotationNotPresent(MapKeyTemporal.class);
    assertAnnotationNotPresent(MapKeyEnumerated.class);
    assertAnnotationNotPresent(MapKeyColumn.class);
    assertAnnotationNotPresent(MapKeyJoinColumns.class);
    assertAnnotationNotPresent(MapKeyJoinColumn.class);
    assertAnnotationNotPresent(AttributeOverride.class);
    assertAnnotationPresent(AttributeOverrides.class);
    AttributeOverrides overridesAnno = reader.getAnnotation(AttributeOverrides.class);
    AttributeOverride[] overrides = overridesAnno.value();
    assertEquals(2, overrides.length);
    assertEquals("field1", overrides[0].name());
    assertEquals("", overrides[0].column().name());
    assertFalse(overrides[0].column().unique());
    assertTrue(overrides[0].column().nullable());
    assertTrue(overrides[0].column().insertable());
    assertTrue(overrides[0].column().updatable());
    assertEquals("", overrides[0].column().columnDefinition());
    assertEquals("", overrides[0].column().table());
    assertEquals(255, overrides[0].column().length());
    assertEquals(0, overrides[0].column().precision());
    assertEquals(0, overrides[0].column().scale());
    assertEquals("field2", overrides[1].name());
    assertEquals("col1", overrides[1].column().name());
    assertTrue(overrides[1].column().unique());
    assertFalse(overrides[1].column().nullable());
    assertFalse(overrides[1].column().insertable());
    assertFalse(overrides[1].column().updatable());
    assertEquals("int", overrides[1].column().columnDefinition());
    assertEquals("table1", overrides[1].column().table());
    assertEquals(50, overrides[1].column().length());
    assertEquals(2, overrides[1].column().precision());
    assertEquals(1, overrides[1].column().scale());
}
Also used : AttributeOverrides(jakarta.persistence.AttributeOverrides) AttributeOverride(jakarta.persistence.AttributeOverride) Test(org.junit.Test)

Example 10 with AttributeOverrides

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

the class Ejb3XmlManyToManyTest method testSingleMapKeyAttributeOverride.

/**
 * When there's a single map key attribute override, we still wrap it with
 * an AttributeOverrides annotation.
 */
@Test
public void testSingleMapKeyAttributeOverride() throws Exception {
    reader = getReader(Entity3.class, "field1", "many-to-many.orm10.xml");
    assertAnnotationPresent(ManyToMany.class);
    assertAnnotationNotPresent(MapKey.class);
    assertAnnotationNotPresent(MapKeyClass.class);
    assertAnnotationNotPresent(MapKeyTemporal.class);
    assertAnnotationNotPresent(MapKeyEnumerated.class);
    assertAnnotationNotPresent(MapKeyColumn.class);
    assertAnnotationNotPresent(MapKeyJoinColumns.class);
    assertAnnotationNotPresent(MapKeyJoinColumn.class);
    assertAnnotationNotPresent(AttributeOverride.class);
    assertAnnotationPresent(AttributeOverrides.class);
    AttributeOverrides overridesAnno = reader.getAnnotation(AttributeOverrides.class);
    AttributeOverride[] overrides = overridesAnno.value();
    assertEquals(1, overrides.length);
    assertEquals("field1", overrides[0].name());
    assertEquals("col1", overrides[0].column().name());
}
Also used : AttributeOverrides(jakarta.persistence.AttributeOverrides) AttributeOverride(jakarta.persistence.AttributeOverride) Test(org.junit.Test)

Aggregations

AttributeOverride (jakarta.persistence.AttributeOverride)11 AttributeOverrides (jakarta.persistence.AttributeOverrides)11 Test (org.junit.Test)9 Column (jakarta.persistence.Column)1 JoinColumn (jakarta.persistence.JoinColumn)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)1 JaxbAttributeOverride (org.hibernate.boot.jaxb.mapping.spi.JaxbAttributeOverride)1