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

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

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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top