Tanya Sah
Tanya Sah

Reputation: 151

I have a field in database which I do not want to map in my spring java model while making a get call

I have a database table in which there is a field which I do not want to map to my model class while making a get call. Is there any annotation to handle this use case?

Upvotes: 1

Views: 663

Answers (1)

Ismail
Ismail

Reputation: 1316

When persisting Java objects into database records using an Object-Relational Mapping (ORM) framework, we can ignore fields by adding the @Transient annotation to those fields.

@Entity
@Table(name = "Users")
public class User {

    @Id
    private Integer id;
 
    private String email;
 
    private String password;
 
    @Transient
    private Date loginTime;
    
    // getters and setters
}

Upvotes: 1

Related Questions