I am using Spring JPA and Spring Data Rest with SpringBoot. I have a DB table called user and an entity for this table. I have no controller for this application.
@Entity
@Table(name = "USER")
public class User implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "USER_ID")
private Integer userid;
@Basic(optional = false)
@Column(name = "USER_NAME")
private String username;
}
And now, I need to add one more field which isn't a column in the USER table. It will be used by some monitoring tool for tracing purpose.
@Entity
@Table(name = "USER")
public class User implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "USER_ID")
private Integer userid;
@Basic(optional = false)
@Column(name = "USER_NAME")
private String username;
private String tracer; // this field is not in DB
}
I am getting a jdbc.spi.SqlExceptionHelper - Invalid column name "tracer" after adding this field, which makes sense because this class is annotated as an entity. My question is that: is there a way to add a non-db field into an entity class? I guess not, but would like to know in case someone has a solution. Thanks.