From 009380a0f3e5c05b1410fd88a4e6da5c96bc079e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Westk=C3=A4mper?= Date: Thu, 14 Oct 2010 10:30:11 +0000 Subject: [PATCH] #660353 : fixed identifier handling --- .../hibernate/HibernateDomainExporter.java | 6 +- .../query/jpa/domain2/DocumentProp.java | 2 - .../com/mysema/query/jpa/domain3/Store.java | 89 +++++++++++++++++++ .../HibernateDomainExporterTest.java | 23 ++++- querydsl-jpa/src/test/resources/store.hbm.xml | 33 +++++++ 5 files changed, 146 insertions(+), 7 deletions(-) create mode 100644 querydsl-jpa/src/test/java/com/mysema/query/jpa/domain3/Store.java create mode 100644 querydsl-jpa/src/test/resources/store.hbm.xml diff --git a/querydsl-jpa/src/main/java/com/mysema/query/jpa/hibernate/HibernateDomainExporter.java b/querydsl-jpa/src/main/java/com/mysema/query/jpa/hibernate/HibernateDomainExporter.java index 8b86fa501..3ce296274 100644 --- a/querydsl-jpa/src/main/java/com/mysema/query/jpa/hibernate/HibernateDomainExporter.java +++ b/querydsl-jpa/src/main/java/com/mysema/query/jpa/hibernate/HibernateDomainExporter.java @@ -152,7 +152,10 @@ public class HibernateDomainExporter { EntityType entityType = createEntityType(pc.getMappedClass()); if (pc.getDeclaredIdentifierProperty() != null){ handleProperty(entityType, pc.getMappedClass(), pc.getDeclaredIdentifierProperty()); - } + }else if (!pc.isInherited() && pc.hasIdentifierProperty()){ + System.out.println(entityType.toString() + pc.getIdentifierProperty()); + handleProperty(entityType, pc.getMappedClass(), pc.getIdentifierProperty()); + } Iterator properties = pc.getDeclaredPropertyIterator(); while (properties.hasNext()){ handleProperty(entityType, pc.getMappedClass(), (org.hibernate.mapping.Property) properties.next()); @@ -239,6 +242,7 @@ public class HibernateDomainExporter { } private Map,Annotation> getAnnotations(Class cl, String propertyName) throws NoSuchMethodException { + // TODO : merge annotations try { Field field = cl.getDeclaredField(propertyName); return getAnnotations(field.getAnnotations()); diff --git a/querydsl-jpa/src/test/java/com/mysema/query/jpa/domain2/DocumentProp.java b/querydsl-jpa/src/test/java/com/mysema/query/jpa/domain2/DocumentProp.java index 7420505ae..9ad62077f 100644 --- a/querydsl-jpa/src/test/java/com/mysema/query/jpa/domain2/DocumentProp.java +++ b/querydsl-jpa/src/test/java/com/mysema/query/jpa/domain2/DocumentProp.java @@ -52,7 +52,5 @@ public class DocumentProp { public void setPropValueDetails(String propValueDetails) { this.propValueDetails = propValueDetails; } - - } diff --git a/querydsl-jpa/src/test/java/com/mysema/query/jpa/domain3/Store.java b/querydsl-jpa/src/test/java/com/mysema/query/jpa/domain3/Store.java new file mode 100644 index 000000000..39305aee0 --- /dev/null +++ b/querydsl-jpa/src/test/java/com/mysema/query/jpa/domain3/Store.java @@ -0,0 +1,89 @@ +package com.mysema.query.jpa.domain3; + +import java.io.Serializable; + +public class Store implements Serializable { + + private static final long serialVersionUID = 7221730732392000227L; + + private String code; + + private String name; + + private String address; + + private String city; + + private String phoneDetails; + + private String faxDetails; + + private String zipCode; + + private String chainCode; + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getPhoneDetails() { + return phoneDetails; + } + + public void setPhoneDetails(String phoneDetails) { + this.phoneDetails = phoneDetails; + } + + public String getFaxDetails() { + return faxDetails; + } + + public void setFaxDetails(String faxDetails) { + this.faxDetails = faxDetails; + } + + public String getZipCode() { + return zipCode; + } + + public void setZipCode(String zipCode) { + this.zipCode = zipCode; + } + + public String getChainCode() { + return chainCode; + } + + public void setChainCode(String chainCode) { + this.chainCode = chainCode; + } + +} \ No newline at end of file diff --git a/querydsl-jpa/src/test/java/com/mysema/query/jpa/hibernate/HibernateDomainExporterTest.java b/querydsl-jpa/src/test/java/com/mysema/query/jpa/hibernate/HibernateDomainExporterTest.java index dd1d7a7a1..c2035da43 100644 --- a/querydsl-jpa/src/test/java/com/mysema/query/jpa/hibernate/HibernateDomainExporterTest.java +++ b/querydsl-jpa/src/test/java/com/mysema/query/jpa/hibernate/HibernateDomainExporterTest.java @@ -24,7 +24,7 @@ public class HibernateDomainExporterTest { private SerializerConfig serializerConfig = SimpleSerializerConfig.getConfig(Domain.class.getPackage().getAnnotation(Config.class)); @Test - public void Execute_Single() throws IOException { + public void Execute_Contact() throws IOException { FileUtils.deleteDirectory(new File("target/gen1")); File contact = new File("src/test/resources/contact.hbm.xml"); Configuration config = new Configuration(); @@ -34,11 +34,11 @@ public class HibernateDomainExporterTest { exporter.execute(); File targetFile = new File("target/gen1/com/mysema/query/jpa/domain2/QContact.java"); - assertContains(targetFile, "StringPath firstName", "StringPath lastName"); + assertContains(targetFile, "NumberPath id", "StringPath firstName", "StringPath lastName"); } @Test - public void Execute_Single2() throws IOException { + public void Execute_Contact2() throws IOException { FileUtils.deleteDirectory(new File("target/gen2")); File contact = new File("src/test/resources/contact2.hbm.xml"); Configuration config = new Configuration(); @@ -48,7 +48,7 @@ public class HibernateDomainExporterTest { exporter.execute(); File targetFile = new File("target/gen2/com/mysema/query/jpa/domain2/QContact.java"); - assertContains(targetFile, "StringPath firstName", "StringPath lastName"); + assertContains(targetFile, "NumberPath id", "StringPath firstName", "StringPath lastName"); } @Test @@ -108,6 +108,21 @@ public class HibernateDomainExporterTest { } } + + + @Test + public void Execute_Store() throws IOException { + FileUtils.deleteDirectory(new File("target/gen5")); + File contact = new File("src/test/resources/store.hbm.xml"); + Configuration config = new Configuration(); + config.addFile(contact); + config.buildMappings(); + HibernateDomainExporter exporter = new HibernateDomainExporter("Q", new File("target/gen5"), config); + exporter.execute(); + + File targetFile = new File("target/gen5/com/mysema/query/jpa/domain3/QStore.java"); + assertContains(targetFile, "StringPath code"); + } private static void assertContains(File file, String... strings) throws IOException{ assertTrue(file.getPath() + " doesn't exist", file.exists()); diff --git a/querydsl-jpa/src/test/resources/store.hbm.xml b/querydsl-jpa/src/test/resources/store.hbm.xml new file mode 100644 index 000000000..0da34b349 --- /dev/null +++ b/querydsl-jpa/src/test/resources/store.hbm.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file