Hibernate 用@TableGenerator 生成Id

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;
    }
   
}

阅读更多
个人分类: Hibernate
上一篇android service
下一篇jar 包详解
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭