From 7ad0fcc5afdea8901074af4c871addcbe3790826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Westk=C3=A4mper?= Date: Tue, 25 Sep 2012 23:14:26 +0300 Subject: [PATCH] further fixes --- .../jpa/codegen/HibernateDomainExporter.java | 16 ++++++++-------- .../query/jpa/domain11/DomainExporterTest.java | 4 +++- .../com/mysema/query/jpa/domain11/domain.hbm.xml | 5 ++++- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/querydsl-jpa-codegen/src/main/java/com/mysema/query/jpa/codegen/HibernateDomainExporter.java b/querydsl-jpa-codegen/src/main/java/com/mysema/query/jpa/codegen/HibernateDomainExporter.java index 7697eb6b8..0c211534b 100644 --- a/querydsl-jpa-codegen/src/main/java/com/mysema/query/jpa/codegen/HibernateDomainExporter.java +++ b/querydsl-jpa-codegen/src/main/java/com/mysema/query/jpa/codegen/HibernateDomainExporter.java @@ -40,6 +40,7 @@ import javax.xml.stream.XMLStreamException; import org.hibernate.cfg.Configuration; import org.hibernate.mapping.Component; import org.hibernate.mapping.KeyValue; +import org.hibernate.mapping.ManyToOne; import org.hibernate.mapping.MappedSuperclass; import org.hibernate.mapping.OneToMany; import org.hibernate.mapping.PersistentClass; @@ -326,7 +327,7 @@ public class HibernateDomainExporter { handleProperty(embeddedType, embeddedType.getJavaClass(), (org.hibernate.mapping.Property)properties.next()); } propertyType = embeddedType; - } else if (propertyType.getCategory() == TypeCategory.ENTITY) { + } else if (propertyType.getCategory() == TypeCategory.ENTITY || p.getValue() instanceof ManyToOne) { propertyType = createEntityType(propertyType); } else if (propertyType.getCategory() == TypeCategory.CUSTOM) { propertyType = createEmbeddableType(propertyType); @@ -346,8 +347,7 @@ public class HibernateDomainExporter { while (properties.hasNext()) { handleProperty(embeddedType, embeddedClass, (org.hibernate.mapping.Property)properties.next()); } - } - + } } AnnotatedElement annotated = getAnnotatedElement(cl, p.getName()); Property property = createProperty(entityType, p.getName(), propertyType, annotated); @@ -392,9 +392,9 @@ public class HibernateDomainExporter { } private EntityType createEntityType(Type type, Map types) { - String rawName = type.getJavaClass().getName(); - if (types.containsKey(rawName)) { - return types.get(rawName); + String rawName = type.getFullName(); + if (allTypes.containsKey(rawName)) { + return allTypes.get(rawName); } else { EntityType entityType = new EntityType(type); typeMappings.register(entityType, queryTypeFactory.create(entityType)); @@ -409,8 +409,8 @@ public class HibernateDomainExporter { } private EntityType createEntityType(Class cl, Map types) { - if (types.containsKey(cl.getName())) { - return types.get(cl.getName()); + if (allTypes.containsKey(cl.getName())) { + return allTypes.get(cl.getName()); } else { EntityType type = new EntityType(new ClassType(TypeCategory.ENTITY, cl)); typeMappings.register(type, queryTypeFactory.create(type)); diff --git a/querydsl-jpa-codegen/src/test/java/com/mysema/query/jpa/domain11/DomainExporterTest.java b/querydsl-jpa-codegen/src/test/java/com/mysema/query/jpa/domain11/DomainExporterTest.java index b49cb96de..85a6d9644 100644 --- a/querydsl-jpa-codegen/src/test/java/com/mysema/query/jpa/domain11/DomainExporterTest.java +++ b/querydsl-jpa-codegen/src/test/java/com/mysema/query/jpa/domain11/DomainExporterTest.java @@ -27,9 +27,11 @@ public class DomainExporterTest { assertTrue(new File(gen, "com/mysema/query/jpa/domain11/QOtherthing.java").exists()); assertTrue(new File(gen, "com/mysema/query/jpa/domain11/QSomething.java").exists()); - String str = Files.toString(new File(gen, "com/mysema/query/jpa/domain11/QSomething.java"), Charsets.UTF_8); + String str = Files.toString(new File(gen, "com/mysema/query/jpa/domain11/QOtherthing.java"), Charsets.UTF_8); assertTrue(str.contains("QSomething")); + str = Files.toString(new File(gen, "com/mysema/query/jpa/domain11/QSomething.java"), Charsets.UTF_8); + assertTrue(str.contains("id")); } } diff --git a/querydsl-jpa-codegen/src/test/resources/com/mysema/query/jpa/domain11/domain.hbm.xml b/querydsl-jpa-codegen/src/test/resources/com/mysema/query/jpa/domain11/domain.hbm.xml index 4c3be1b8a..40f62b43f 100644 --- a/querydsl-jpa-codegen/src/test/resources/com/mysema/query/jpa/domain11/domain.hbm.xml +++ b/querydsl-jpa-codegen/src/test/resources/com/mysema/query/jpa/domain11/domain.hbm.xml @@ -6,14 +6,17 @@ - + + + + \ No newline at end of file