Search in sources :

Example 16 with JoinTable

use of javax.persistence.JoinTable in project hibernate-orm by hibernate.

the class Ejb3XmlManyToManyTest method testJoinTableNoChildren.

@Test
public void testJoinTableNoChildren() throws Exception {
    reader = getReader(Entity2.class, "field1", "many-to-many.orm16.xml");
    assertAnnotationPresent(ManyToMany.class);
    assertAnnotationPresent(JoinTable.class);
    assertAnnotationNotPresent(JoinColumns.class);
    assertAnnotationNotPresent(JoinColumn.class);
    JoinTable joinTableAnno = reader.getAnnotation(JoinTable.class);
    assertEquals("", joinTableAnno.catalog());
    assertEquals("", joinTableAnno.name());
    assertEquals("", joinTableAnno.schema());
    assertEquals(0, joinTableAnno.joinColumns().length);
    assertEquals(0, joinTableAnno.inverseJoinColumns().length);
    assertEquals(0, joinTableAnno.uniqueConstraints().length);
}
Also used : JoinTable(javax.persistence.JoinTable) Test(org.junit.Test)

Example 17 with JoinTable

use of javax.persistence.JoinTable in project hibernate-orm by hibernate.

the class Ejb3XmlOneToManyTest method testJoinTableAllChildren.

@Test
public void testJoinTableAllChildren() throws Exception {
    reader = getReader(Entity2.class, "field1", "one-to-many.orm17.xml");
    assertAnnotationPresent(OneToMany.class);
    assertAnnotationPresent(JoinTable.class);
    assertAnnotationNotPresent(JoinColumns.class);
    assertAnnotationNotPresent(JoinColumn.class);
    JoinTable joinTableAnno = reader.getAnnotation(JoinTable.class);
    assertEquals("cat1", joinTableAnno.catalog());
    assertEquals("table1", joinTableAnno.name());
    assertEquals("schema1", joinTableAnno.schema());
    // JoinColumns
    JoinColumn[] joinColumns = joinTableAnno.joinColumns();
    assertEquals(2, joinColumns.length);
    assertEquals("", joinColumns[0].name());
    assertEquals("", joinColumns[0].referencedColumnName());
    assertEquals("", joinColumns[0].table());
    assertEquals("", joinColumns[0].columnDefinition());
    assertTrue(joinColumns[0].insertable());
    assertTrue(joinColumns[0].updatable());
    assertTrue(joinColumns[0].nullable());
    assertFalse(joinColumns[0].unique());
    assertEquals("col1", joinColumns[1].name());
    assertEquals("col2", joinColumns[1].referencedColumnName());
    assertEquals("table2", joinColumns[1].table());
    assertEquals("int", joinColumns[1].columnDefinition());
    assertFalse(joinColumns[1].insertable());
    assertFalse(joinColumns[1].updatable());
    assertFalse(joinColumns[1].nullable());
    assertTrue(joinColumns[1].unique());
    // InverseJoinColumns
    JoinColumn[] inverseJoinColumns = joinTableAnno.inverseJoinColumns();
    assertEquals(2, inverseJoinColumns.length);
    assertEquals("", inverseJoinColumns[0].name());
    assertEquals("", inverseJoinColumns[0].referencedColumnName());
    assertEquals("", inverseJoinColumns[0].table());
    assertEquals("", inverseJoinColumns[0].columnDefinition());
    assertTrue(inverseJoinColumns[0].insertable());
    assertTrue(inverseJoinColumns[0].updatable());
    assertTrue(inverseJoinColumns[0].nullable());
    assertFalse(inverseJoinColumns[0].unique());
    assertEquals("col3", inverseJoinColumns[1].name());
    assertEquals("col4", inverseJoinColumns[1].referencedColumnName());
    assertEquals("table3", inverseJoinColumns[1].table());
    assertEquals("int", inverseJoinColumns[1].columnDefinition());
    assertFalse(inverseJoinColumns[1].insertable());
    assertFalse(inverseJoinColumns[1].updatable());
    assertFalse(inverseJoinColumns[1].nullable());
    assertTrue(inverseJoinColumns[1].unique());
    // UniqueConstraints
    UniqueConstraint[] uniqueConstraints = joinTableAnno.uniqueConstraints();
    assertEquals(2, uniqueConstraints.length);
    assertEquals("", uniqueConstraints[0].name());
    assertEquals(1, uniqueConstraints[0].columnNames().length);
    assertEquals("col5", uniqueConstraints[0].columnNames()[0]);
    assertEquals("uq1", uniqueConstraints[1].name());
    assertEquals(2, uniqueConstraints[1].columnNames().length);
    assertEquals("col6", uniqueConstraints[1].columnNames()[0]);
    assertEquals("col7", uniqueConstraints[1].columnNames()[1]);
}
Also used : MapKeyJoinColumn(javax.persistence.MapKeyJoinColumn) JoinColumn(javax.persistence.JoinColumn) UniqueConstraint(javax.persistence.UniqueConstraint) JoinTable(javax.persistence.JoinTable) Test(org.junit.Test)

Example 18 with JoinTable

use of javax.persistence.JoinTable in project hibernate-orm by hibernate.

the class Ejb3XmlManyToManyTest method testJoinTableAllChildren.

@Test
public void testJoinTableAllChildren() throws Exception {
    reader = getReader(Entity2.class, "field1", "many-to-many.orm17.xml");
    assertAnnotationPresent(ManyToMany.class);
    assertAnnotationPresent(JoinTable.class);
    assertAnnotationNotPresent(JoinColumns.class);
    assertAnnotationNotPresent(JoinColumn.class);
    JoinTable joinTableAnno = reader.getAnnotation(JoinTable.class);
    assertEquals("cat1", joinTableAnno.catalog());
    assertEquals("table1", joinTableAnno.name());
    assertEquals("schema1", joinTableAnno.schema());
    // JoinColumns
    JoinColumn[] joinColumns = joinTableAnno.joinColumns();
    assertEquals(2, joinColumns.length);
    assertEquals("", joinColumns[0].name());
    assertEquals("", joinColumns[0].referencedColumnName());
    assertEquals("", joinColumns[0].table());
    assertEquals("", joinColumns[0].columnDefinition());
    assertTrue(joinColumns[0].insertable());
    assertTrue(joinColumns[0].updatable());
    assertTrue(joinColumns[0].nullable());
    assertFalse(joinColumns[0].unique());
    assertEquals("col1", joinColumns[1].name());
    assertEquals("col2", joinColumns[1].referencedColumnName());
    assertEquals("table2", joinColumns[1].table());
    assertEquals("int", joinColumns[1].columnDefinition());
    assertFalse(joinColumns[1].insertable());
    assertFalse(joinColumns[1].updatable());
    assertFalse(joinColumns[1].nullable());
    assertTrue(joinColumns[1].unique());
    // InverseJoinColumns
    JoinColumn[] inverseJoinColumns = joinTableAnno.inverseJoinColumns();
    assertEquals(2, inverseJoinColumns.length);
    assertEquals("", inverseJoinColumns[0].name());
    assertEquals("", inverseJoinColumns[0].referencedColumnName());
    assertEquals("", inverseJoinColumns[0].table());
    assertEquals("", inverseJoinColumns[0].columnDefinition());
    assertTrue(inverseJoinColumns[0].insertable());
    assertTrue(inverseJoinColumns[0].updatable());
    assertTrue(inverseJoinColumns[0].nullable());
    assertFalse(inverseJoinColumns[0].unique());
    assertEquals("col3", inverseJoinColumns[1].name());
    assertEquals("col4", inverseJoinColumns[1].referencedColumnName());
    assertEquals("table3", inverseJoinColumns[1].table());
    assertEquals("int", inverseJoinColumns[1].columnDefinition());
    assertFalse(inverseJoinColumns[1].insertable());
    assertFalse(inverseJoinColumns[1].updatable());
    assertFalse(inverseJoinColumns[1].nullable());
    assertTrue(inverseJoinColumns[1].unique());
    // UniqueConstraints
    UniqueConstraint[] uniqueConstraints = joinTableAnno.uniqueConstraints();
    assertEquals(2, uniqueConstraints.length);
    assertEquals("", uniqueConstraints[0].name());
    assertEquals(1, uniqueConstraints[0].columnNames().length);
    assertEquals("col5", uniqueConstraints[0].columnNames()[0]);
    assertEquals("uq1", uniqueConstraints[1].name());
    assertEquals(2, uniqueConstraints[1].columnNames().length);
    assertEquals("col6", uniqueConstraints[1].columnNames()[0]);
    assertEquals("col7", uniqueConstraints[1].columnNames()[1]);
}
Also used : MapKeyJoinColumn(javax.persistence.MapKeyJoinColumn) JoinColumn(javax.persistence.JoinColumn) UniqueConstraint(javax.persistence.UniqueConstraint) JoinTable(javax.persistence.JoinTable) Test(org.junit.Test)

Example 19 with JoinTable

use of javax.persistence.JoinTable in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method buildAssociationOverrides.

private List<AssociationOverride> buildAssociationOverrides(Element element, XMLContext.Default defaults) {
    List<Element> subelements = element == null ? null : element.elements("association-override");
    List<AssociationOverride> overrides = new ArrayList<AssociationOverride>();
    if (subelements != null && subelements.size() > 0) {
        for (Element current : subelements) {
            AnnotationDescriptor override = new AnnotationDescriptor(AssociationOverride.class);
            copyStringAttribute(override, current, "name", true);
            override.setValue("joinColumns", getJoinColumns(current, false));
            JoinTable joinTable = buildJoinTable(current, defaults);
            if (joinTable != null) {
                override.setValue("joinTable", joinTable);
            }
            overrides.add((AssociationOverride) AnnotationFactory.create(override));
        }
    }
    return overrides;
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) AssociationOverride(javax.persistence.AssociationOverride) AnnotatedElement(java.lang.reflect.AnnotatedElement) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) JoinTable(javax.persistence.JoinTable)

Example 20 with JoinTable

use of javax.persistence.JoinTable in project hibernate-orm by hibernate.

the class Ejb3XmlManyToOneTest method testJoinTableNoChildren.

@Test
public void testJoinTableNoChildren() throws Exception {
    reader = getReader(Entity1.class, "field1", "many-to-one.orm4.xml");
    assertAnnotationPresent(ManyToOne.class);
    assertAnnotationNotPresent(JoinColumn.class);
    assertAnnotationNotPresent(JoinColumns.class);
    assertAnnotationPresent(JoinTable.class);
    JoinTable joinTableAnno = reader.getAnnotation(JoinTable.class);
    assertEquals("", joinTableAnno.catalog());
    assertEquals("", joinTableAnno.name());
    assertEquals("", joinTableAnno.schema());
    assertEquals(0, joinTableAnno.joinColumns().length);
    assertEquals(0, joinTableAnno.inverseJoinColumns().length);
    assertEquals(0, joinTableAnno.uniqueConstraints().length);
}
Also used : JoinTable(javax.persistence.JoinTable) Test(org.junit.Test)

Aggregations

JoinTable (javax.persistence.JoinTable)28 JoinColumn (javax.persistence.JoinColumn)18 Test (org.junit.Test)9 Field (java.lang.reflect.Field)8 Method (java.lang.reflect.Method)8 ManyToMany (javax.persistence.ManyToMany)8 UniqueConstraint (javax.persistence.UniqueConstraint)7 ReflectUtil (org.eweb4j.util.ReflectUtil)7 MapKeyJoinColumn (javax.persistence.MapKeyJoinColumn)6 OneToMany (javax.persistence.OneToMany)6 DAOException (org.eweb4j.orm.dao.DAOException)6 PrimaryKeyJoinColumn (javax.persistence.PrimaryKeyJoinColumn)4 HashMap (java.util.HashMap)3 AssociationOverride (javax.persistence.AssociationOverride)3 CollectionTable (javax.persistence.CollectionTable)3 ElementCollection (javax.persistence.ElementCollection)3 ManyToOne (javax.persistence.ManyToOne)3 AnnotationException (org.hibernate.AnnotationException)3 XClass (org.hibernate.annotations.common.reflection.XClass)3 File (java.io.File)2