现在的位置: 首页 > 综合 > 正文

主键自增

2013年10月07日 ⁄ 综合 ⁄ 共 331字 ⁄ 字号 评论关闭

public class PKGen implements IdentifierGenerator {

static int validateCount = 1;
static long currentKey = -1;

public Serializable generate(SessionImplementor session , Object arg1)
throws HibernateException {
long cur = System.currentTimeMillis();
if (cur == currentKey) {
cur+=validateCount;
currentKey=cur;
validateCount++;
} else {
            validateCount=1;
}
return cur;

}

抱歉!评论已关闭.