public OrgType createOrgType(String name, Session session) { OrgType existing = orgType(name); if (existing != null) { throw new RuntimeException("An organisation type with that name already exists"); } Organisation parent = getOrganisation(); while (parent != null) { if (parent.orgType(name) != null) { throw new RuntimeException( "An organisation type with that name exists in a parent organisation: " + parent.getOrgId()); } parent = parent.getOrganisation(); } OrgType ot = new OrgType(); ot.setName(name); ot.setDisplayName(name); ot.setOrganisation(this); getOrgTypes().add(ot); session.save(this); session.save(ot); return ot; }