ClientRepository clientRepo = getRepository(ClientRepository.class);
getEntityManager().getTransaction().begin();
// Create and save a resourceServer
ResourceServer resourceServer = new ResourceServer();
resourceServer.setKey("key");
resourceServer.setName("name");
resourceServer.setSecret("sec");
resourceServer.setContactName("contact");
resourceServer.setScopes(Arrays.asList("read"));
resourceServer = repo.save(resourceServer);
// Create and save a client, associated with the resourceServer
Client c = new Client();
c.setName("name");
c.setClientId("clientid");
c.setSecret(UUID.randomUUID().toString());
c.setResourceServer(resourceServer);
resourceServer.setClients(new HashSet(Arrays.asList(c)));
c = clientRepo.save(c);
getEntityManager().getTransaction().commit();
// See that the client can be found
assertNotNull(clientRepo.findOne(c.getId()));
long resourceServerId = resourceServer.getId();
// Remove the resourceServer
getEntityManager().getTransaction().begin();
repo.delete(resourceServer);
getEntityManager().getTransaction().commit();