From: Kai Moritz Date: Sat, 31 Aug 2013 06:51:03 +0000 (+0200) Subject: Fixed NPE when using nested classes in entities with @EmbeddedId/@Embeddable X-Git-Tag: hibernate4-maven-plugin-1.0.3~20 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=da0b3041b8fbcba6175d05a2561b38c365111ed8;p=hibernate-maven-plugin Fixed NPE when using nested classes in entities with @EmbeddedId/@Embeddable Patch supplied by Eduard Szente Details: ---------------- Hi, when using your plugin for schema export the presence of nested classes in entities (e.g. when using @EmbeddedId/@Embeddable and defining the Id within the target entity class) yields to NPEs. public class Entity { @EmbeddedId private Id id; @Embeddable public static class Id implements Serializable { .... } } Entity.Id.class.getSimplename == "Id", while the compiled class is named "Entity$Id.class" Patch appended. Best regards, Eduard --- diff --git a/pom.xml b/pom.xml index e291e61f..80516763 100644 --- a/pom.xml +++ b/pom.xml @@ -53,6 +53,10 @@ Lorenzo Nicora lorenzo.nicora@nicus.it + + Eduard Szente + eduard.szente@gmail.com + diff --git a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java index f66f5249..313c127b 100644 --- a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java +++ b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java @@ -386,9 +386,11 @@ public class Hbm2DdlMojo extends AbstractMojo { Class annotatedClass = classLoader.loadClass(name); classes.add(annotatedClass); + String resourceName = annotatedClass.getName(); + resourceName = resourceName.substring(resourceName.lastIndexOf(".") + 1, resourceName.length()) + ".class"; InputStream is = annotatedClass - .getResourceAsStream(annotatedClass.getSimpleName() + ".class"); + .getResourceAsStream(resourceName); byte[] buffer = new byte[1024*4]; // copy data in 4MB-chunks int i; while((i = is.read(buffer)) > -1)