#235 fixed supertype handling in HibernateDomainExporter

This commit is contained in:
Timo Westkämper 2012-09-27 00:27:40 +03:00
parent 7ad0fcc5af
commit a5cffabbd9
5 changed files with 75 additions and 0 deletions

View File

@ -47,6 +47,7 @@ import org.hibernate.mapping.PersistentClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.collect.Sets;
import com.mysema.codegen.CodeWriter;
import com.mysema.codegen.JavaWriter;
import com.mysema.codegen.model.ClassType;
@ -312,6 +313,18 @@ public class HibernateDomainExporter {
}
}
// go through supertypes
Set<Supertype> additions = Sets.newHashSet();
for (Map.Entry<String, EntityType> entry : allTypes.entrySet()) {
EntityType entityType = entry.getValue();
if (entityType.getSuperType() != null && !allTypes.containsKey(entityType.getSuperType().getType().getFullName())) {
additions.add(entityType.getSuperType());
}
}
for (Supertype type : additions) {
type.setEntityType(createEntityType(type.getType(), superTypes));
}
}
private void handleProperty(EntityType entityType, Class<?> cl, org.hibernate.mapping.Property p)

View File

@ -0,0 +1,29 @@
package com.mysema.query.jpa.domain12;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import org.hibernate.cfg.Configuration;
import org.junit.Test;
import com.mysema.query.jpa.codegen.HibernateDomainExporter;
import com.mysema.util.FileUtils;
public class DomainExporterTest {
@Test
public void Execute() throws IOException {
File gen = new File("target/" + getClass().getSimpleName());
FileUtils.delete(gen);
Configuration config = new Configuration();
config.addFile(new File("src/test/resources/com/mysema/query/jpa/domain12/domain.hbm.xml"));
HibernateDomainExporter exporter = new HibernateDomainExporter("Q", gen, config);
exporter.execute();
assertTrue(new File(gen, "com/mysema/query/jpa/domain12/QEntity.java").exists());
assertTrue(new File(gen, "com/mysema/query/jpa/domain12/QSupertype.java").exists());
}
}

View File

@ -0,0 +1,9 @@
package com.mysema.query.jpa.domain12;
public class Entity extends Supertype {
String id;
Entity entity;
}

View File

@ -0,0 +1,6 @@
package com.mysema.query.jpa.domain12;
public class Supertype {
String property;
}

View File

@ -0,0 +1,18 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-access="field" package="com.mysema.query.jpa.domain12">
<class name="Entity" table="Entity">
<id name="id" type="string" length="40"/>
<property name="property" type="string"/>
<many-to-one name="entity" class="Entity" lazy="false" fetch="join">
<column name="SOMETHING_ID" length="40" />
</many-to-one>
</class>
</hibernate-mapping>