JBoss.org Community Documentation

- Prev
- Next

### 7.2. Collections

For this tutorial, start two instances of the demo GUI. In this tutorial, we will:

- Attach a POJO to the cache and see it being replicated.
- Set a Collection attribute in this POJO
- Manipulate this Collection attribute and see the changes visible in the GUI and being replicated
- Detach a POJO from the cache.

1. In the 1st GUI instance, create a POJO with a Collection attribute:

          joe = new Person();
          joe.setName("Joe Black");

          lang = new ArrayList();
          lang.add("Spanish");

          joe.setLanguages(lang);

2. Attach the POJO to the cache:

          cache.attach("pojo/joe", joe);

3. Get a proxy reference to the Collection and add a new element to it:

          proxyLang = joe.getLanguages();
          proxyLang.add("English");

4. Detach the pojo from the cache:

          cache.detach("pojo/joe");

5. Use the proxy reference to the Collection to add another element and see how this does not get added to the cache:

          proxyLang.add("French");

- Prev7.1. POJO Cache API, POJO manipulation, and Repli...
- Top of page
- Front page
- Next8. Transactions