Menu

#15 Wired-Lifecycle-Methods under TX-Control can be problematic

open
nobody
5
2005-08-30
2005-08-30
Anonymous
No

The wired-Lifecycle Methods "_wiredCreate" and
"_setWiredContext" are executed within a transaction
context, depending on the TX-attribute in the component
descriptor (component-jar.xml).

Very often it is suitable to use the the
Required-TX-Attribute for each method (using the *
wildcard in the component descriptor), i.e. the
wired-Lifecycle-Methods use this TX-attribute
(Required), too.

If any of the components that work in one TX context
with Required attribute produces a RuntimeException no
other component in the same TX-context can lookup
another component that also has the Required TX-attribute.

Example:

public class CompA ... {

public void foo() {
//lookup CompB
try {
compB.bar();
catch(Exception e) {
//lookup CompC
compC.doSomeExceptionHandling();
}
}
}

public class CompB ... {
public void bar() {
//do something that produces a runtime exception
}
}

This example causes a cuba.ComponentException
"transaction rolled back" because the container
automatically sets the TX to rollback only if a
RuntimeException occurs.

To make the example work, the TX-attributes for the
wired Lifecycle-methods have to be set in the component
descriptor:

<container-transaction attribute="RequiresNew"
method-name="_wiredCreate"/>
<container-transaction attribute="RequiresNew"
method-name="_setWiredContext"/>

But that means that technology-specific methods are
described in a descriptor that is technology idependent.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB