use of org.hibernate.type.ManyToOneType in project jbosstools-hibernate by jbosstools.
the class TypeFacadeTest method testIsOneToOne.
@Test
public void testIsOneToOne() {
IType typeFacade = null;
ClassType classType = new ClassType();
typeFacade = FACADE_FACTORY.createType(classType);
Assert.assertFalse(typeFacade.isOneToOne());
EntityType entityType = new ManyToOneType(null, null);
typeFacade = FACADE_FACTORY.createType(entityType);
Assert.assertFalse(entityType.isOneToOne());
OneToOneType oneToOneType = new OneToOneType(null, null, null, false, null, false, false, null, null);
typeFacade = FACADE_FACTORY.createType(oneToOneType);
Assert.assertTrue(oneToOneType.isOneToOne());
}
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(null, null);
typeFacade = FACADE_FACTORY.createType(entityType);
Assert.assertTrue(entityType.isEntityType());
}
use of org.hibernate.type.ManyToOneType in project hibernate-orm by hibernate.
the class AbstractPropertyMapping method getCommonType.
private Type getCommonType(MetadataImplementor metadata, EntityType entityType1, EntityType entityType2) {
PersistentClass thisClass = metadata.getEntityBinding(entityType1.getAssociatedEntityName());
PersistentClass otherClass = metadata.getEntityBinding(entityType2.getAssociatedEntityName());
PersistentClass commonClass = getCommonPersistentClass(thisClass, otherClass);
if (commonClass == null) {
return null;
}
// Create a copy of the type but with the common class
if (entityType1 instanceof ManyToOneType) {
ManyToOneType t = (ManyToOneType) entityType1;
return new ManyToOneType(t, commonClass.getEntityName());
} else if (entityType1 instanceof SpecialOneToOneType) {
SpecialOneToOneType t = (SpecialOneToOneType) entityType1;
return new SpecialOneToOneType(t, commonClass.getEntityName());
} else if (entityType1 instanceof OneToOneType) {
OneToOneType t = (OneToOneType) entityType1;
return new OneToOneType(t, commonClass.getEntityName());
} else {
throw new IllegalStateException("Unexpected entity type: " + entityType1);
}
}
use of org.hibernate.type.ManyToOneType in project hibernate-orm by hibernate.
the class ASTParserLoadingTest method testSelectClauseImplicitJoinOrderByJoinedProperty.
@Test
@TestForIssue(jiraKey = "HHH-9305")
@SuppressWarnings({ "unchecked" })
public void testSelectClauseImplicitJoinOrderByJoinedProperty() {
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 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(3, zoos.size());
assertEquals(otherZoo.getName(), zoos.get(0).getName());
assertEquals(2, zoos.get(0).getMammals().size());
assertEquals(2, zoos.get(0).getAnimals().size());
assertSame(zoos.get(0), zoos.get(1));
assertEquals(zoo.getName(), zoos.get(2).getName());
assertEquals(1, zoos.get(2).getMammals().size());
assertEquals(1, zoos.get(2).getAnimals().size());
s.clear();
s.delete(plat);
s.delete(zebra);
s.delete(elephant);
s.delete(zoo);
s.delete(otherZoo);
t.commit();
s.close();
}
use of org.hibernate.type.ManyToOneType in project hibernate-orm by hibernate.
the class ASTParserLoadingTest method testSelectClauseImplicitJoin.
@Test
@SuppressWarnings({ "unchecked" })
public void testSelectClauseImplicitJoin() {
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);
s.persist(plat);
s.persist(zoo);
s.flush();
s.clear();
Query q = s.createQuery("select distinct a.zoo from Animal a where a.zoo is not null");
Type type = q.getReturnTypes()[0];
assertTrue(type instanceof ManyToOneType);
assertEquals(((ManyToOneType) type).getAssociatedEntityName(), "org.hibernate.test.hql.Zoo");
zoo = (Zoo) q.list().get(0);
assertEquals(zoo.getMammals().size(), 1);
assertEquals(zoo.getAnimals().size(), 1);
s.clear();
s.delete(plat);
s.delete(zoo);
t.commit();
s.close();
}
Aggregations