public Organisation createChildOrg(String orgId, String title, Session session) { Organisation o = new Organisation(); o.setOrganisation(this); if (orgId != null) { orgId = orgId.trim(); if (orgId.length() == 0) { orgId = null; } } o.setOrgId(orgId); o.setTitle(title); o.setCreatedDate(new Date()); o.setModifiedDate(new Date()); if (this.getChildOrgs() == null) { this.setChildOrgs(new ArrayList<>()); } this.getChildOrgs().add(o); session.save(o); if (o.getOrgId() == null || o.getOrgId().trim().length() == 0) { findUniqueOrgId(o, session); session.save(o); } SubOrg.updateSubOrgs(o, session); return o; }