Java JPA序列ID为String

时间:2014-10-02 14:23:14

标签: java hibernate jpa

这是我目前拥有的,工作正常

@Id
@SequenceGenerator(name="EDGE_DEAL_BOOKING_EDGEDEALNUMBER_GENERATOR", sequenceName="EDGEDEALNUM_SEQ")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="EDGE_DEAL_BOOKING_EDGEDEALNUMBER_GENERATOR")
private int edgedealnumber;

public int getEdgedealnumber() {
    return this.edgedealnumber;
}

public void setEdgedealnumber(int edgedealnumber) {
    this.edgedealnumber = edgedealnumber;
}

然而,对于ID我需要它是一个带字符串前缀的字符串,即。 EDGE12345。我试图将代码切换到:

@Id
@SequenceGenerator(name="EDGE_DEAL_BOOKING_EDGEDEALNUMBER_GENERATOR", sequenceName="EDGEDEALNUM_SEQ")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="EDGE_DEAL_BOOKING_EDGEDEALNUMBER_GENERATOR")
private String edgedealnumber;

public String getEdgedealnumber() {
    return this.edgedealnumber;
}

public void setEdgedealnumber(String edgedealnumber) {
    this.edgedealnumber = "EDG"+edgedealnumber;
}

但它给出了

org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.String

0 个答案:

没有答案