关闭

Hibernate 用@TableGenerator 生成Id

232人阅读 评论(0) 收藏 举报
分类:

package com.bjsxt.hibernate;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.SequenceGenerator;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

//本例有两个Generator
@Entity
@TableGenerator(
        name="Teacher_GEN",
        table="GENERATOR_TABLE",   
        pkColumnName = "pk_key",
        valueColumnName = "pk_value",
        pkColumnValue="Teacher",//从pk_key=Teacher的pk_value
        allocationSize=1//每一次拿出就出加多少
    )
/**
 *
 * 表: GENERATOR_TABLE
 *  pk_key            pk_value
 *  Teacher           1
 */
public class Teacher {
    private int id;
    private String name;
    private String title;

 
    @Id
    @GeneratedValue(strategy=GenerationType.TABLE, generator="Teacher_GEN")
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
   
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
   
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:14249次
    • 积分:656
    • 等级:
    • 排名:千里之外
    • 原创:52篇
    • 转载:10篇
    • 译文:0篇
    • 评论:0条
    文章分类