Background: I'm using Sparx Enterprise Architect 8.0. When I mark a member of a domain class as transient
, the resulting generated code uses the volatile
keyword instead of transient
. This is correct according to Enterprise Architect Java conventions.
How can I define transient attributes using EA and have the generated code to use the Java transient
keyword for them?
Define a tagged value on the attribute (not the class), named transient
with value true
.
This works in 9.1; unfortunately I don't have an 8.0 installation to try this on. You can check it yourself by looking at the relevant generation template: select Settings - Code Generation Templates, then pick Java in the language drop-down (top left). In the Templates list, find the one called "Attribute Declaration."
If there is a line starting with %attTag:"transient"
, the above should work. If not, you can add it yourself if you know how (code generation templates are not a good area for experimentation), but I don't want to post Sparx-copyrighted material here.
Sadly, using tagged values on attributes means you can't see this property in diagrams or the project browser. That's just a fact of life, but it might be worth the bother to hassle Sparx about putting in some sort of way of showing attribute tags.