Fixed NPE when using nested classes in entities with @EmbeddedId/@Embeddable
authorKai Moritz <kai@juplo.de>
Sat, 31 Aug 2013 06:51:03 +0000 (08:51 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 31 Aug 2013 06:52:48 +0000 (08:52 +0200)
Patch supplied by Eduard Szente <eduard.szente@gmail.com>

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
src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java

diff --git a/pom.xml b/pom.xml
index e291e61..8051676 100644 (file)
--- a/pom.xml
+++ b/pom.xml
       <name>Lorenzo Nicora</name>
       <email>lorenzo.nicora@nicus.it</email>
     </contributor>
+    <contributor>
+      <name>Eduard Szente</name>
+      <email>eduard.szente@gmail.com</email>
+    </contributor>
   </contributors>
 
   <distributionManagement>
index f66f524..313c127 100644 (file)
@@ -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)