[英]Hibernate: Add a property in my class that is not mapped to a db-table
[英]property in domain class not mapped to a table
我想向域 class 添加一个属性,以便使用 class 的属性进行计算:
@Entity
@Table(name="tablename")
public class MyDomainClass {
int id;
int property1;
int property2;
@Id
@GeneratedValue
@Column(name="id")
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
@Column(name="property1")
public int getProperty1() {
return this.property1;
}
public void setProperty1(int property1) {
this.property1= property1;
}
public int getProperty2() {
;doSomething
return this.property2;
}
public void setProperty2(int property2) {
this.property2= property2;
}
我不希望将 property2 映射到表“tablename”,但实际上它是。
我该如何解决?
我需要从 jsp 访问这个属性,例如 domainclass.property2
使用@Transient
注解指定属性不是持久的:
@Transient
private int property2;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.