It is a lock that allows code to either access/analyze structural elements of java sources, or modify them. If you access the model, you need to acquire the transaction lock - it guarantees that no modifications will be made to the model by other code/threads while your code is in it. If you're seeing InvalidObjectExceptions, you're probably accessing model objects outside of the transaction lock.

Here is how it is typically used for write access:

 // true = write transaction
JavaMetamodel.getDefaultRepository().beginTrans(true); 
boolean rollback = true;

try {

    //do something
    // ....
    // if everything succeeded
    // set rollback to false
    rollback = false;

} finally {
    JavaMetamodel.getDefaultRepository().endTrans(rollback);
}

Here is how it is typically used for read access:
// false = read transaction
JavaMetamodel.getDefaultRepository().beginTrans(false); 
try {
   //do something
} finally {
   JavaMetamodel.getDefaultRepository().endTrans();
}

Source: NetBeans FAQ