2012-08-14 24 views
0

我的代碼是: -想前置自動生成利用用戶提供的字符串,JPA Id值或休眠

@Id 
//@SequenceGenerator(name = "non_distributor", sequenceName="nd") 
@GeneratedValue 

public int getNondistid() 
{ 
    return nondistid; 
} 
public void setNondistid(int nondistid) 
{ 
    this.nondistid = nondistid; 
} 

它是在數字生成的值id爲1,2,3,但我想,自動生成的ID必須如下所示: - 「nd_01」或「nd1」。 所以請提供建議如何使用註釋生成相同的內容。

回答

0
@Id 
@GeneratedValue(strategy=GenerationType.AUTO) 
@Column(name="fooId") 
private Integer id; 
0
@Entity 
public class News implements Serializable { 

    @Id 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private Long id; 
} 

TABLE SQL:: 
create table News (id bigint not null primary key (id)); 
+0

試過,但不產生價值所需的ID ...我要創造價值ID爲「ND_1」假設爲nondistributor ID – 2012-08-14 07:09:06