mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-24 21:07:26 +08:00
#235 fixed supertype handling in HibernateDomainExporter
This commit is contained in:
parent
7ad0fcc5af
commit
a5cffabbd9
@ -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)
|
||||
|
||||
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package com.mysema.query.jpa.domain12;
|
||||
|
||||
public class Entity extends Supertype {
|
||||
|
||||
String id;
|
||||
|
||||
Entity entity;
|
||||
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
package com.mysema.query.jpa.domain12;
|
||||
|
||||
public class Supertype {
|
||||
|
||||
String property;
|
||||
}
|
||||
@ -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>
|
||||
Loading…
Reference in New Issue
Block a user