The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

arizona (1) [Avatar] Offline
#1
I am trying to understand the @TransactionScoped Annotation. I build a simple app and annotated the class Gauge with it:

@TransactionScoped
public class Gauge {
void measure() {
}

private int temp = 0;

public int temperature() {
return temp;
}
}


Launching the app like this shows me no real benefit of this annotation (i think it is not working).


public class PowerStation {

Transaction transaction;
Chamber chamber1 = new Chamber();
Chamber chamber2 = new Chamber();
Chamber chamber3 = new Chamber();

public void start() {
//transaction.begin();

TransactionModule module = new TransactionModule();
Injector injector = Guice.createInjector(new Module[]{module});

boolean failed = false;
try {
chamber1.fire();
chamber2.fire();
chamber3.fire();

} catch (StartFailedException e) {
failed = true;
} finally {
if (failed) {
//transaction.rollback();
} else {
//transaction.commit();
}
}
}
}


So what is wrong?