Hibernate 注解配置

package cn.com.songjy.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;


@Entity
@Table(name="T_USER",schema="SCOTT")//在用户SCOTT的下表名为T_USER
public class User implements Serializable {

	private static final long serialVersionUID = 8373486895856607204L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="USER_SEQUENCE")
	@SequenceGenerator(name="USER_SEQUENCE", sequenceName="USER_SEQUENCE_SCOTT",allocationSize=1)
	@Column(name="USER_ID")
	private Long id;
	
	@Column(name="USER_NAME",length=20)
	private String name;
	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
}
/*
 * 在hibernate.cfg.xml中加入如下代码即可
 * <mapping class="cn.com.songjy.domain.User"/>
 */

基于按annotation的hibernate主键生成策略
Hibernate综合示例

你可能感兴趣的:(注解,Hibernate)