比如我有一个表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)先谢谢大家了。
-------------------------------
列名 数据类型 允许NULL 主键
id int no 自动增长
custId int no yes
name varchar(50) no yes
address varchar(100) yes no--------------------------
custId和name为主键,但我又想id这个字段设为自动增长类型,这种情况下jpa应该如何写才可以让这个非主键id字段为自动增长类型的呢?(我的数据库是sybase)先谢谢大家了。
解决方案 »
- 各位大哥,谁有在线费用报销系统啊!急用啊!
- entity 怎么定义组合主键
- Hibernate中报‘调用中无效的参数’怎么回事?
- 如何给一个普通的Java类创建一个Init初始化方法
- axis返回值如果是一个类要怎么做?
- java编译结果没有获取对象名称和属性值???急求解答
- xwork.xml由webwork里面的那段代码装载进去的?
- 单态模式问题
- ██急██Struts超怪问题████同一jsp页面,我在Struts中Forward跳转的和直接打开的不一致是为什么呢?
- STRUTS 问题 "HelloWord.jsp": org.apache.jasper.compiler.ParseException: End of content reached while more parsing required: tag
- WebSphere配置Oracle数据源,通过JNDI获取数据源出错
- 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;
}
..................................
}我目前大概这样写的,但是有问题
custId int no yes
这2个有重复之嫌
id 设为主键 custId和name建立唯一约束就行了
如果不能改表结构 哪就在程序里自己控制吧
说少了一点,我的资料是把A数据库的cust表和B数据库的cust表union起来,得到最终的结果。因为分页问题,所以才没有在程式里控制。
不建议这么做
从B库取出的编号前强行加上类似“B_”前缀
这样就不重复了,呵呵~
xxx.setYYY(id);
session.update(xxx);
那要不加这样:
从A库取出的编号后强行加上类似“_A”后缀
从B库取出的编号后强行加上类似“_B”后缀要不排序就不按编号来排,例如按录入时间来排
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID",nullable=false,insertable=false,updatable=false,columnDefinition="numeric(19,0) IDENTITY")
public Long getId() {
return super.getId();
}