Java 如何设置由两个字段串联而成的JPA实体列?
我正在使用Jpa并尝试将字符串写入一列,该字符串是字符串与整数的串联 我试图在Java 如何设置由两个字段串联而成的JPA实体列?,java,jpa,concatenation,entity,Java,Jpa,Concatenation,Entity,我正在使用Jpa并尝试将字符串写入一列,该字符串是字符串与整数的串联 我试图在实体中这样做: @Transient Integer x = 555; // Just as an example @Transient String y = "abcd"; // Just as an example @Access(AccessType.PROPERTY) @Column(name = "identifier") private String user
实体中这样做
:
@Transient
Integer x = 555; // Just as an example
@Transient
String y = "abcd"; // Just as an example
@Access(AccessType.PROPERTY)
@Column(name = "identifier")
private String userID() {
return x + y;
}
public void setUserID(String y, int x) {
this.y = y;
this.x = x;
}
但是在我的列userID
中没有设置任何内容,我希望找到555abcd
,但我的值为空
我错过了什么
@使用Transient是因为我不想存储x和y(在这个实体中我没有一个名为y的列),但我有一个列
标识符,我怀疑原因是以下一个或多个:(1)命名与bean命名不一致:应该是getUserId()
,并有一个相应的setter获取字符串
;当前setter采用(字符串,int)
。(2) 访问器是私有的。(3) 不确定,但为什么要保留两个独立的@Transient
字段?您可以对映射到DB列的单个字段使用字段访问,setter只需设置该字段:@column(name=“identifier”)私有字符串标识符;setUserID(字符串y,int x){identifier=x+y;}