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