user1454308
user1454308

Reputation: 33

Ignore field from database Spring Roo

I have a spring roo web service that I am currently building out but I have an entity that contains a field that should not be included in the database.

I would like the field to be in the entity and print it out with JSON to string methods, but I don't need that value saved. Is there any annotation or hack to make this happen?

Upvotes: 3

Views: 736

Answers (1)

seanhodges
seanhodges

Reputation: 17524

Spring Roo uses JPA for persistence. You want to mark the field as @Transient:

@RooJavaBean
@RooEntity
class MyEntity {

    private String column1;

    @Transient
    private String ignoreMe; // Ignore this field in JPA

}

You can also use the same annotation for bean methods that would otherwise be mapped:

@RooJavaBean
@RooEntity
class MyEntity {

    private String column1;

    @Transient
    private String getAsJSON() {
        return JSONHelper.toJSON(column1);
    }

}

Upvotes: 2

Related Questions