要使用jpa或hibernate自动生成以用户提供的字符串开头的Id值吗
我的代码是:-要使用jpa或hibernate自动生成以用户提供的字符串开头的Id值吗,hibernate,jpa,Hibernate,Jpa,我的代码是:- @Id //@SequenceGenerator(name = "non_distributor", sequenceName="nd") @GeneratedValue public int getNondistid() { return nondistid; } public void setNondistid(int nondistid) { this.nondistid = nondistid; } 它正在生成数字为1、2、3的id值,但我希望自动生
@Id
//@SequenceGenerator(name = "non_distributor", sequenceName="nd")
@GeneratedValue
public int getNondistid()
{
return nondistid;
}
public void setNondistid(int nondistid)
{
this.nondistid = nondistid;
}
它正在生成数字为1、2、3的id值,但我希望自动生成的id必须类似:-“nd_01”或“nd1”。
因此,请给出如何使用注释生成相同id的建议。尝试了此操作,但没有生成所需的id值…我想为非分发者id生成id值为“nd_1”
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="fooId")
private Integer id;
@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));