Search in sources :

Example 11 with ManyToOneType

use of org.hibernate.type.ManyToOneType in project jbosstools-hibernate by jbosstools.

the class TypeFacadeTest method testGetAssociatedEntityName.

@Test
public void testGetAssociatedEntityName() {
    IType typeFacade = null;
    ClassType classType = new ClassType();
    typeFacade = FACADE_FACTORY.createType(classType);
    Assert.assertNull(typeFacade.getAssociatedEntityName());
    EntityType entityType = new ManyToOneType((TypeScope) null, "foo");
    typeFacade = FACADE_FACTORY.createType(entityType);
    Assert.assertEquals("foo", typeFacade.getAssociatedEntityName());
}
Also used : EntityType(org.hibernate.type.EntityType) ManyToOneType(org.hibernate.type.ManyToOneType) ClassType(org.hibernate.type.ClassType) IType(org.jboss.tools.hibernate.runtime.spi.IType) Test(org.junit.Test)

Example 12 with ManyToOneType

use of org.hibernate.type.ManyToOneType in project jbosstools-hibernate by jbosstools.

the class TypeFacadeTest method testIsEntityType.

@Test
public void testIsEntityType() {
    IType typeFacade = null;
    ClassType classType = new ClassType();
    typeFacade = FACADE_FACTORY.createType(classType);
    Assert.assertFalse(typeFacade.isEntityType());
    EntityType entityType = new ManyToOneType((TypeScope) null, null);
    typeFacade = FACADE_FACTORY.createType(entityType);
    Assert.assertTrue(entityType.isEntityType());
}
Also used : EntityType(org.hibernate.type.EntityType) ManyToOneType(org.hibernate.type.ManyToOneType) ClassType(org.hibernate.type.ClassType) IType(org.jboss.tools.hibernate.runtime.spi.IType) Test(org.junit.Test)

Example 13 with ManyToOneType

use of org.hibernate.type.ManyToOneType in project jbosstools-hibernate by jbosstools.

the class TypeFacadeTest method testGetAssociatedEntityName.

@Test
public void testGetAssociatedEntityName() {
    IType typeFacade = null;
    ClassType classType = new ClassType();
    typeFacade = FACADE_FACTORY.createType(classType);
    Assert.assertNull(typeFacade.getAssociatedEntityName());
    EntityType entityType = new ManyToOneType(null, "foo");
    typeFacade = FACADE_FACTORY.createType(entityType);
    Assert.assertEquals("foo", typeFacade.getAssociatedEntityName());
}
Also used : EntityType(org.hibernate.type.EntityType) ManyToOneType(org.hibernate.type.ManyToOneType) ClassType(org.hibernate.type.ClassType) IType(org.jboss.tools.hibernate.runtime.spi.IType) Test(org.junit.Test)

Example 14 with ManyToOneType

use of org.hibernate.type.ManyToOneType in project jbosstools-hibernate by jbosstools.

the class TypeFacadeTest method testGetAssociatedEntityName.

@Test
public void testGetAssociatedEntityName() {
    IType typeFacade = null;
    ClassType classType = new ClassType();
    typeFacade = FACADE_FACTORY.createType(classType);
    Assert.assertNull(typeFacade.getAssociatedEntityName());
    EntityType entityType = new ManyToOneType(null, "foo");
    typeFacade = FACADE_FACTORY.createType(entityType);
    Assert.assertEquals("foo", typeFacade.getAssociatedEntityName());
}
Also used : EntityType(org.hibernate.type.EntityType) ManyToOneType(org.hibernate.type.ManyToOneType) ClassType(org.hibernate.type.ClassType) IType(org.jboss.tools.hibernate.runtime.spi.IType) Test(org.junit.Test)

Example 15 with ManyToOneType

use of org.hibernate.type.ManyToOneType in project hibernate-orm by hibernate.

the class ASTParserLoadingTest method testSelectClauseDistinctImplicitJoinOrderByJoinedProperty.

@Test
@SuppressWarnings({ "unchecked" })
public void testSelectClauseDistinctImplicitJoinOrderByJoinedProperty() {
    Session s = openSession();
    Transaction t = s.beginTransaction();
    Zoo zoo = new Zoo();
    zoo.setName("The Zoo");
    zoo.setMammals(new HashMap());
    zoo.setAnimals(new HashMap());
    Mammal plat = new Mammal();
    plat.setBodyWeight(11f);
    plat.setDescription("Platypus");
    plat.setZoo(zoo);
    plat.setSerialNumber("plat123");
    zoo.getMammals().put("Platypus", plat);
    zoo.getAnimals().put("plat123", plat);
    Zoo otherZoo = new Zoo();
    otherZoo.setName("The Other Zoo");
    otherZoo.setMammals(new HashMap());
    otherZoo.setAnimals(new HashMap());
    Mammal zebra = new Mammal();
    zebra.setBodyWeight(110f);
    zebra.setDescription("Zebra");
    zebra.setZoo(otherZoo);
    zebra.setSerialNumber("zebra123");
    otherZoo.getMammals().put("Zebra", zebra);
    otherZoo.getAnimals().put("zebra123", zebra);
    Mammal elephant = new Mammal();
    elephant.setBodyWeight(550f);
    elephant.setDescription("Elephant");
    elephant.setZoo(otherZoo);
    elephant.setSerialNumber("elephant123");
    otherZoo.getMammals().put("Elephant", elephant);
    otherZoo.getAnimals().put("elephant123", elephant);
    s.persist(plat);
    s.persist(zoo);
    s.persist(zebra);
    s.persist(elephant);
    s.persist(otherZoo);
    s.flush();
    s.clear();
    Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null order by a.zoo.name");
    Type type = q.getReturnTypes()[0];
    assertTrue(type instanceof ManyToOneType);
    assertEquals(((ManyToOneType) type).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo");
    List<Zoo> zoos = (List<Zoo>) q.list();
    assertEquals(2, zoos.size());
    assertEquals(otherZoo.getName(), zoos.get(0).getName());
    assertEquals(2, zoos.get(0).getMammals().size());
    assertEquals(2, zoos.get(0).getAnimals().size());
    assertEquals(zoo.getName(), zoos.get(1).getName());
    assertEquals(1, zoos.get(1).getMammals().size());
    assertEquals(1, zoos.get(1).getAnimals().size());
    s.clear();
    s.delete(plat);
    s.delete(zebra);
    s.delete(elephant);
    s.delete(zoo);
    s.delete(otherZoo);
    t.commit();
    s.close();
}
Also used : DiscriminatorType(org.hibernate.persister.entity.DiscriminatorType) ManyToOneType(org.hibernate.type.ManyToOneType) ComponentType(org.hibernate.type.ComponentType) Type(org.hibernate.type.Type) Transaction(org.hibernate.Transaction) TransactionUtil2.inTransaction(org.hibernate.testing.transaction.TransactionUtil2.inTransaction) Query(org.hibernate.Query) HashMap(java.util.HashMap) ManyToOneType(org.hibernate.type.ManyToOneType) List(java.util.List) ArrayList(java.util.ArrayList) Session(org.hibernate.Session) Test(org.junit.Test)

Aggregations

ManyToOneType (org.hibernate.type.ManyToOneType)35 Test (org.junit.Test)28 ClassType (org.hibernate.type.ClassType)24 EntityType (org.hibernate.type.EntityType)24 IType (org.jboss.tools.hibernate.runtime.spi.IType)24 OneToOneType (org.hibernate.type.OneToOneType)11 Type (org.hibernate.type.Type)9 ComponentType (org.hibernate.type.ComponentType)7 HashMap (java.util.HashMap)4 Query (org.hibernate.Query)4 Session (org.hibernate.Session)4 Transaction (org.hibernate.Transaction)4 DiscriminatorType (org.hibernate.persister.entity.DiscriminatorType)4 TransactionUtil2.inTransaction (org.hibernate.testing.transaction.TransactionUtil2.inTransaction)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 PersistentClass (org.hibernate.mapping.PersistentClass)2 CollectionType (org.hibernate.type.CollectionType)2 SetType (org.hibernate.type.SetType)2 Element (org.dom4j.Element)1