Answer the question
In order to leave comments, you need to log in
Is it possible to add custom field to @Entity class?
In spring data jpa, is it possible to add a field to the Entity class that is not in the database? If so, how to do it correctly, because in this form I get an error (the balanceChange field is not in the database):
@Entity
@Table(name = "profile", schema = "webmaster")
public class Webmaster extends Profile {
@Id
@GeneratedValue
@Column(name = "id")
protected Integer id;
@Column(name = "balance")
Integer balance;
@Column(name = "hash")
String hash;
@Column(name = "currency")
String currency;
@Column(name = "status")
String isActive;
@Column(name = "title")
String title;
@Column(name = "purse")
String purse;
private double balanceChange;
public Webmaster() {
}
Answer the question
In order to leave comments, you need to log in
Yes, you can, but of course it will not be saved to the database! Give it the transient
keyword transient private double balanceChange;
If you have Hibernate use this annotation https://docs.jboss.org/hibernate/stable/annotation... . But the field value will not be saved to the database. Such fields are used when you use entities without a DTO layer and want to transfer data calculated on the server.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question