changeset 26:5e24413d355b

Fixed bug that deleted all attributes in the system if a relation had id=null :-(
author Robert Casties <casties@mpiwg-berlin.mpg.de>
date Fri, 05 Aug 2016 22:02:18 +0200
parents c23ae718fdd3
children 8ea716da439f
files src/main/java/org/mpi/openmind/repository/bo/Entity.java src/main/java/org/mpi/openmind/repository/services/AbstractPersistenceService.java src/main/java/org/mpi/openmind/repository/services/PersistenceService.java
diffstat 3 files changed, 32 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/mpi/openmind/repository/bo/Entity.java	Thu Aug 04 21:16:08 2016 +0200
+++ b/src/main/java/org/mpi/openmind/repository/bo/Entity.java	Fri Aug 05 22:02:18 2016 +0200
@@ -348,7 +348,7 @@
     	if(oldRel != null){
     		
     		Exception ex = new Exception(
-    				"This entity has already this relation [\n" +
+    				"This entity has already this (source) relation [\n" +
 					toString() + "\n" +
 					"NewRel=" + srcRel + "\n" +
 					"OldRel=" + oldRel + "]");
@@ -364,7 +364,7 @@
     	Relation oldRel = this.containsTarRel(tarRel);
     	if(oldRel != null){
     		Exception ex = new Exception(
-    				"This entity has already this relation [\n" +
+    				"This entity has already this (target) relation [\n" +
 					toString() + "\n" +
 					"NewRel=" + tarRel + "\n" +
 					"OldRel=" + oldRel + "]");
--- a/src/main/java/org/mpi/openmind/repository/services/AbstractPersistenceService.java	Thu Aug 04 21:16:08 2016 +0200
+++ b/src/main/java/org/mpi/openmind/repository/services/AbstractPersistenceService.java	Fri Aug 05 22:02:18 2016 +0200
@@ -1055,9 +1055,14 @@
 			entity.setSourceRelations(new ArrayList<Relation>());
 			entity.setTargetRelations(new ArrayList<Relation>());
 
+            // FIXME: getNodes finds all attributes if id=null!
+            if (entity.getId() == null) {
+                logger.error("Relation with id=null! Abort loading attributes.");
+                return entity;
+            }
+			
 			// getting Attributes and SourceRelations
-			List<Node> nodes = null; 
-					
+			List<Node> nodes = null; 					
 			if(considerTimeModif){
 				nodes = this.getNodes(session, null,
 						entity.getSystemStatus(), entity.getId(),
@@ -1075,6 +1080,11 @@
 				} else if (node instanceof Relation) {
 					Relation rel = (Relation) node;
 					// new attr for relations
+					// FIXME: getNodes finds all attributes if id=null!
+		            if (rel.getId() == null) {
+		                logger.error("Relation with id=null! Abort loading attributes.");
+		                continue;
+		            }
 					List<Node> attrs = this.getNodes(session, null,
 							rel.getSystemStatus(), rel.getId(),
 							rel.getModificationTime(), null, null);
@@ -1113,6 +1123,11 @@
 				if (node instanceof Relation) {
 					Relation rel = (Relation) node;
 					// new attr for relations
+		            // FIXME: getNodes finds all attributes if id=null!
+		            if (rel.getId() == null) {
+		                logger.error("Relation with id=null! Abort loading attributes.");
+		                continue;
+		            }
 					List<Node> attrs = this.getNodes(session, null,
 							rel.getSystemStatus(), rel.getId(),
 							rel.getModificationTime(), null, null);
--- a/src/main/java/org/mpi/openmind/repository/services/PersistenceService.java	Thu Aug 04 21:16:08 2016 +0200
+++ b/src/main/java/org/mpi/openmind/repository/services/PersistenceService.java	Fri Aug 05 22:02:18 2016 +0200
@@ -299,6 +299,11 @@
 
 		// loading attributes
 		for (Relation rel : relations) {
+		    // FIXME: getNodes finds all attributes if id=null!
+            if (rel.getId() == null) {
+                logger.error("Relation with id=null! Abort loading attributes.");
+                continue;
+            }
 			List<Node> attrs = this.getNodes(session, null,
 					rel.getSystemStatus(), rel.getId(),
 					rel.getModificationTime(), null, null);
@@ -528,6 +533,11 @@
 			}
 			// loading attributes
 			for (Relation rel : relations) {
+	            // FIXME: getNodes finds all attributes if id=null!
+	            if (rel.getId() == null) {
+	                logger.error("Relation with id=null! Abort loading attributes.");
+	                continue;
+	            }
 				List<Node> attrs = this.getNodes(session, null,
 						rel.getSystemStatus(), rel.getId(),
 						rel.getModificationTime(), null, null);
@@ -1379,10 +1389,9 @@
 					hql += " OR ";
 			}
 
-            /* ROC: led to hibernate errors
-             * hql += " ) group by att.sourceId order by ent.ownValue";
-             */
-            hql += " ) order by ent.ownValue";
+            /* ROC: led to hibernate errors */
+           hql += " ) group by att.sourceId order by ent.ownValue";
+           // hql += " ) order by ent.ownValue";
 
 			Query query = session.createQuery(hql);
 			if (maxResult > 0)