diff --git a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/LinkToParentTreeDatasourceService.java b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/LinkToParentTreeDatasourceService.java
--- a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/LinkToParentTreeDatasourceService.java
+++ b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/LinkToParentTreeDatasourceService.java
@@ -236,7 +236,7 @@
     boolean allowNotApplyingWhereClauseToChildren = !tableTree.isApplyWhereClauseToChildNodes();
     if ((fetchRoot || !allowNotApplyingWhereClauseToChildren) && hqlWhereClause != null) {
       // Include the hql where clause for all root nodes and for child nodes only if it is required
-      whereClause.append(hqlWhereClause + " and ");
+      whereClause.append("(" + hqlWhereClause + ") and ");
     }
 
     if (hqlWhereClauseRootNodes != null && fetchRoot) {
@@ -555,7 +555,7 @@
       whereClause.append(".id");
     }
     whereClause.append(" = ? ");
-    whereClause.append(" and " + hqlWhereClause);
+    whereClause.append(" and (" + hqlWhereClause + ")");
     final OBQuery<BaseOBObject> query = OBDal.getInstance().createQuery(entity.getName(),
         whereClause.toString());
 
