Nullpointer exception in TermInitializer and adapted termsDataSet-with_auditing_info.xml
authorAndreas Müller <a.mueller@bgbm.org>
Mon, 8 Jun 2009 16:37:24 +0000 (16:37 +0000)
committerAndreas Müller <a.mueller@bgbm.org>
Mon, 8 Jun 2009 16:37:24 +0000 (16:37 +0000)
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/PersistentTermInitializer.java
cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml

index 74cc41038afd65d54d1e286a4bd3b36c55c2ac5f..ea6e3514e383374abfc2494c542ba9335c22e196 100644 (file)
@@ -105,17 +105,21 @@ public class PersistentTermInitializer extends DefaultTermInitializer {
         * @param termsa <code>Map</code> containing all already \r
         *                                               loaded terms with their <code>UUID</code> as key\r
         */\r
-       protected void secondPass(Class clazz, UUID vocabularyUuid,Map<UUID,DefinedTermBase> terms) {\r
+       protected void secondPass(Class clazz, UUID vocabularyUuid, Map<UUID,DefinedTermBase> terms) {\r
                logger.info("Loading vocabulary for class " + clazz.getSimpleName() + " with uuid " + vocabularyUuid );\r
                \r
                TermVocabulary persistedVocabulary = vocabularyDao.findByUuid(vocabularyUuid);\r
                \r
-               for(Object obj : persistedVocabulary.getTerms()) {\r
-                       DefinedTermBase d = (DefinedTermBase)obj;\r
-                       Hibernate.initialize(d.getRepresentations());\r
-                       terms.put(d.getUuid(), d);                      \r
+               if (persistedVocabulary != null){\r
+                       for(Object obj : persistedVocabulary.getTerms()) {\r
+                               DefinedTermBase d = (DefinedTermBase)obj;\r
+                               Hibernate.initialize(d.getRepresentations());\r
+                               terms.put(d.getUuid(), d);                      \r
+                       }\r
+               }else{\r
+                       logger.error("Persisted Vocabulary does not exist in database: " + vocabularyUuid);\r
+                       throw new NullPointerException("Persisted Vocabulary does not exist in database: " + vocabularyUuid);\r
                }\r
-               \r
                logger.debug("Setting defined Terms for class " + clazz.getSimpleName());\r
                super.setDefinedTerms(clazz, persistedVocabulary);\r
        }\r
index d603f02b9b5420d34616a9966c5fd44f2b1458ad..16e5b243d7f6c4019f69fbd60468b54a71a68ae3 100644 (file)
Binary files a/cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml and b/cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml differ