Let us consider two Grails domain example classes.
1st class:
class Person {
String name
Integer counter = 0
static transients = ['counter']
}
2nd class:
class Vehicle {
String name
transient Integer counter = 0
}
Will there be any difference in GORM persistence or domain class behaviour for the Integer counter field between classes Person and Vehicle?
EDIT: I know that Person class is the good way to do it as referenced by Grails docs. However I would prefer the Vehicle class way as it seems to be more obvious and easier not to overlook when reading a code.
If you have assigned a value to a variable while loading the class then that value will be assigned to the static variable while de-serializing the class but not to transient. So if you are using both of these modifiers with a variable, then in that sense, I am saying that static will take precedent to transient.
If the inertia and damping effects are not important, you might be able to use a static analysis instead. A transient thermal analysis follows basically the same procedures as a steady-state thermal analysis. The main difference is that most applied loads in a transient analysis are functions of time.
However there is no compilation error. transient and final : final variables are directly serialized by their values, so there is no use/impact of declaring final variable as transient. There is no compile-time error though.
When JVM comes across transient keyword, it ignores original value of the variable and save default value of that variable data type. transient keyword plays an important role to meet security constraints. There are various real-life examples where we don’t want to save private data in file.
The two mechanisms define different kinds of "transience". static transients
defines bean properties that should not be mapped to the database by Hibernate, whereas the transient
keyword denotes a field that should not be saved by the Java object serialization mechanism (e.g. when using webflow). They both have their uses in different situations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With