From da0b3041b8fbcba6175d05a2561b38c365111ed8 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 31 Aug 2013 08:51:03 +0200 Subject: [PATCH] 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 --- pom.xml | 4 ++++ src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) 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) -- 2.20.1