Is there any difference between 'static transients' and 'transient Type aField' declaration for GORM?

StackOverflow https://stackoverflow.com/questions/12462205

Question

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.

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top