Search in sources :

Example 1 with ManyToOne

use of org.hibernate.mapping.ManyToOne in project hibernate-orm by hibernate.

the class CollectionMetadataGenerator method addCollection.

void addCollection() {
    final Type type = propertyValue.getType();
    final Value value = propertyValue.getElement();
    final boolean oneToManyAttachedType = type instanceof BagType || type instanceof SetType || type instanceof MapType || type instanceof ListType;
    final boolean inverseOneToMany = (value instanceof OneToMany) && (propertyValue.isInverse());
    final boolean owningManyToOneWithJoinTableBidirectional = (value instanceof ManyToOne) && (propertyAuditingData.getRelationMappedBy() != null);
    final boolean fakeOneToManyBidirectional = (value instanceof OneToMany) && (propertyAuditingData.getAuditMappedBy() != null);
    if (oneToManyAttachedType && (inverseOneToMany || fakeOneToManyBidirectional || owningManyToOneWithJoinTableBidirectional)) {
        // A one-to-many relation mapped using @ManyToOne and @OneToMany(mappedBy="...")
        addOneToManyAttached(fakeOneToManyBidirectional);
    } else {
        // All other kinds of relations require a middle (join) table.
        addWithMiddleTable();
    }
}
Also used : ListType(org.hibernate.type.ListType) ManyToOneType(org.hibernate.type.ManyToOneType) MaterializedNClobType(org.hibernate.type.MaterializedNClobType) SetType(org.hibernate.type.SetType) MaterializedClobType(org.hibernate.type.MaterializedClobType) MapType(org.hibernate.type.MapType) ComponentType(org.hibernate.type.ComponentType) SortedSetType(org.hibernate.type.SortedSetType) SortedMapType(org.hibernate.type.SortedMapType) BagType(org.hibernate.type.BagType) Type(org.hibernate.type.Type) SetType(org.hibernate.type.SetType) SortedSetType(org.hibernate.type.SortedSetType) BagType(org.hibernate.type.BagType) ListType(org.hibernate.type.ListType) Value(org.hibernate.mapping.Value) OneToMany(org.hibernate.mapping.OneToMany) MapType(org.hibernate.type.MapType) SortedMapType(org.hibernate.type.SortedMapType) ManyToOne(org.hibernate.mapping.ManyToOne)

Example 2 with ManyToOne

use of org.hibernate.mapping.ManyToOne in project jbosstools-hibernate by jbosstools.

the class ValueFacadeTest method testGetReferencedEntityName.

@Test
public void testGetReferencedEntityName() {
    ManyToOne valueTarget = new ManyToOne(null, null);
    valueFacade = FACADE_FACTORY.createValue(valueTarget);
    Assert.assertNull(valueFacade.getReferencedEntityName());
    valueTarget.setReferencedEntityName("Foo");
    Assert.assertEquals("Foo", valueFacade.getReferencedEntityName());
}
Also used : ManyToOne(org.hibernate.mapping.ManyToOne) Test(org.junit.Test)

Example 3 with ManyToOne

use of org.hibernate.mapping.ManyToOne in project jbosstools-hibernate by jbosstools.

the class ValueFacadeTest method testSetFetchModeJoin.

@Test
public void testSetFetchModeJoin() {
    SimpleValue simpleValueTarget = new SimpleValue(null);
    Assert.assertNotEquals(FetchMode.JOIN, simpleValueTarget.getFetchMode());
    valueFacade = FACADE_FACTORY.createValue(simpleValueTarget);
    valueFacade.setFetchModeJoin();
    Assert.assertNotEquals(FetchMode.JOIN, simpleValueTarget.getFetchMode());
    Collection collectionTarget = new Bag(null, null);
    Assert.assertNotEquals(FetchMode.JOIN, collectionTarget.getFetchMode());
    valueFacade = FACADE_FACTORY.createValue(collectionTarget);
    valueFacade.setFetchModeJoin();
    Assert.assertEquals(FetchMode.JOIN, collectionTarget.getFetchMode());
    ManyToOne manyToOneTarget = new ManyToOne(null, null);
    Assert.assertNotEquals(FetchMode.JOIN, manyToOneTarget.getFetchMode());
    valueFacade = FACADE_FACTORY.createValue(manyToOneTarget);
    valueFacade.setFetchModeJoin();
    Assert.assertEquals(FetchMode.JOIN, manyToOneTarget.getFetchMode());
}
Also used : Collection(org.hibernate.mapping.Collection) Bag(org.hibernate.mapping.Bag) IdentifierBag(org.hibernate.mapping.IdentifierBag) ManyToOne(org.hibernate.mapping.ManyToOne) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Example 4 with ManyToOne

use of org.hibernate.mapping.ManyToOne in project jbosstools-hibernate by jbosstools.

the class ValueFacadeTest method testSetReferencedEntityName.

@Test
public void testSetReferencedEntityName() {
    ManyToOne valueTarget = new ManyToOne(null, null);
    valueFacade = FACADE_FACTORY.createValue(valueTarget);
    Assert.assertNull(valueTarget.getReferencedEntityName());
    valueFacade.setReferencedEntityName("Foo");
    Assert.assertEquals("Foo", valueTarget.getReferencedEntityName());
}
Also used : ManyToOne(org.hibernate.mapping.ManyToOne) Test(org.junit.Test)

Example 5 with ManyToOne

use of org.hibernate.mapping.ManyToOne in project jbosstools-hibernate by jbosstools.

the class ValueFacadeTest method testIsManyToOne.

@Test
public void testIsManyToOne() {
    valueTarget = new SimpleValue(null);
    valueFacade = FACADE_FACTORY.createValue(valueTarget);
    Assert.assertFalse(valueFacade.isManyToOne());
    ManyToOne manyToOne = new ManyToOne(null, null);
    valueFacade = FACADE_FACTORY.createValue(manyToOne);
    Assert.assertTrue(valueFacade.isManyToOne());
}
Also used : ManyToOne(org.hibernate.mapping.ManyToOne) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Aggregations

ManyToOne (org.hibernate.mapping.ManyToOne)48 Test (org.junit.Test)37 SimpleValue (org.hibernate.mapping.SimpleValue)22 Collection (org.hibernate.mapping.Collection)10 Bag (org.hibernate.mapping.Bag)9 IdentifierBag (org.hibernate.mapping.IdentifierBag)9 Component (org.hibernate.mapping.Component)8 Property (org.hibernate.mapping.Property)7 AnnotationException (org.hibernate.AnnotationException)5 AssertionFailure (org.hibernate.AssertionFailure)5 Any (org.hibernate.mapping.Any)5 OneToOne (org.hibernate.mapping.OneToOne)5 PersistentClass (org.hibernate.mapping.PersistentClass)5 XProperty (org.hibernate.annotations.common.reflection.XProperty)4 Ejb3Column (org.hibernate.cfg.Ejb3Column)4 Ejb3JoinColumn (org.hibernate.cfg.Ejb3JoinColumn)4 Join (org.hibernate.mapping.Join)4 OneToMany (org.hibernate.mapping.OneToMany)4 Iterator (java.util.Iterator)3 Column (org.hibernate.mapping.Column)3