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());
}
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());
}
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());
}
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());
}
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();
}
Aggregations