JBoss.org Community Documentation

- Prev
- Next

### 6.4.2. JDK5.0 field level annotations

In Release 2.0, we have added two additional field level annotations for customized behavior. The first one is `@org.jboss.cache.pojo.annotation.Transient` . When applied to a field variable, it has the same effect as the Java language `transient` keyword. That is, PojoCache won't put this field into cache management (and therefore no replication).

The second one is `@org.jboss.cache.pojo.annotation.Serializable` , when applied to a field variable, PojoCache will treat this variable as `Serializable` , even when it is `Replicable` . However, the field will need to implement the `Serializable` interface such that it can be replicated.

Here is a code snippet that illustrates usage of these two annotations. Assuming that you have a Gadget class:

    public class Gadget
    {
       // resource won't be replicated
       @Transient
       Resource resource;

       // specialAddress is treated as a Serializable object but still has object relationship
       @Serializable
       SpecialAddress specialAddress;

       // other state variables
    }

Then when we do:

       Gadget gadget = new Gadget();
       Resource resource = new Resource();
       SpecialAddress specialAddress = new SpecialAddress();

       // setters
       gadget.setResource(resource);
       gadget.setSpecialAddress(specialAddress);

       // put into PojoCache management
       cache1.putObject("/gadget", gadget);

       // retrieve it from another cache instance
       Gadget g2 = (Gadget) cache2.getObject("/gadget");

       // This is should be null because of @Transient tag so it is not replicated.
       g2.getResource();

       SepcialAddress d2 = g2.getSpecialAddress();
       d2.setName("inet"); // This won't get replicated automatically because of @Serializable tag
       ge.setSpecialAddress(d2); // Now this will.

- Prev6.4.1. POJO annotation for instrumentation
- Top of page
- Front page
- Next6.5. Weaving