# HG changeset patch # User Robert Casties # Date 1470427338 -7200 # Node ID 5e24413d355b4b84523793c2e72bf295617c161f # Parent c23ae718fdd322d21bf88649618767f5e583f325 Fixed bug that deleted all attributes in the system if a relation had id=null :-( diff -r c23ae718fdd3 -r 5e24413d355b src/main/java/org/mpi/openmind/repository/bo/Entity.java --- 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 + "]"); diff -r c23ae718fdd3 -r 5e24413d355b src/main/java/org/mpi/openmind/repository/services/AbstractPersistenceService.java --- 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()); entity.setTargetRelations(new ArrayList()); + // 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 nodes = null; - + List 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 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 attrs = this.getNodes(session, null, rel.getSystemStatus(), rel.getId(), rel.getModificationTime(), null, null); diff -r c23ae718fdd3 -r 5e24413d355b src/main/java/org/mpi/openmind/repository/services/PersistenceService.java --- 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 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 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)