jpa 非主键字段如何配置为自动增长类型(困扰多时的问题)
比如我有一个表cust有以下字段:
-------------------------------
列名 数据类型 允许NULL 主键
id int no 自动增长
custId int no yes
name varchar(50) no yes
address varchar(100) yes no
--------------------------
custId和name为主键,但我又想id这个字段设为自动增长类型,这种情况下jpa应该如何写才可以让这个非主键id字段为自动增长类型的呢?(我的数据库是sybase)
先谢谢大家了。
--------------------------------------------------------------------------------
我目前这样写的,但是有问题,不知道这个ID如何写才是正确的写法
custPk.java
----------------------------------
import java.io.Serializable;
public class CustPk implements Serializable {
private static final long serialVersionUID = -7310844877900844920L;
private int custId;
private String name;
public int getCustId(){
return this.custId;
}
public String getName() {
return this.name;
}
public CustPk() {
}
@Override
public int hashCode() {
.................
}
@Override
public boolean equals(Object obj) {
........
}
}
--------------------------------------------------------------------
Cust.java
--------------------------------------------------------------------
@Audited
@Entity
@Table(name = "Cust")
@IdClass(CustPk.class)
public class Cust
{
private static final long serialVersionUID = -3186455049080602773L;
Long id;
int custId;
String name;
String address;
public Cust() {
}
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "ID", insertable=false, updatable=false, precision=19, scale=0, nullable=false)
public Long getId() {
return super.getId();
}
@Id
@Column(name = "custId", length = 10, nullable=false)
public int getCustId() {
return this.custId
}
public void setCustid(int custId){
this.custId = custId;
}
@Id
@Column(name = "name", length = 50, nullable=false)
public String getName() {
return this.name;
}
public void setName(String name){
this.name = name;
}
..................................
}