注解方式将java类与数据库表关联,包括序列自增长

package com.briup.bean;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
//会员类
@Entity
@Table(name = "memberinfo")
public class Memberinfo {
	@Id
	@SequenceGenerator(name="seq_type",sequenceName="SEQ_COMMON")
	@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="seq_type")
	private int id;
	private String nickname;
	private String password;
	private String gender;
	private int age;
	private String email;
	private String provincecity;
	private String address;
	private String phone;
	private String passwordquestion;
	private String passwordanswer;
	private String recommender;
	private int point;
	private Date registerdate;
	private Date latestdate;
	private int status;
	private int isonline;
	@OneToOne
	@JoinColumn(name="gradeid")//指定对应外键
	private Graderecord graderecord;

	public Memberinfo() {
		super();
		// TODO Auto-generated constructor stub
	}

	public Memberinfo(String nickname, String password, String gender, int age,
			String email, String provincecity, String address, String phone,
			String passwordquestion, String passwordanswer, String recommender,
			int point, Date registerdate, Date latestdate, int status,
			int isonline, Graderecord graderecord) {
		super();
		this.nickname = nickname;
		this.password = password;
		this.gender = gender;
		this.age = age;
		this.email = email;
		this.provincecity = provincecity;
		this.address = address;
		this.phone = phone;
		this.passwordquestion = passwordquestion;
		this.passwordanswer = passwordanswer;
		this.recommender = recommender;
		this.point = point;
		this.registerdate = registerdate;
		this.latestdate = latestdate;
		this.status = status;
		this.isonline = isonline;
		this.graderecord = graderecord;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getProvincecity() {
		return provincecity;
	}

	public void setProvincecity(String provincecity) {
		this.provincecity = provincecity;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getPasswordquestion() {
		return passwordquestion;
	}

	public void setPasswordquestion(String passwordquestion) {
		this.passwordquestion = passwordquestion;
	}

	public String getPasswordanswer() {
		return passwordanswer;
	}

	public void setPasswordanswer(String passwordanswer) {
		this.passwordanswer = passwordanswer;
	}

	public String getRecommender() {
		return recommender;
	}

	public void setRecommender(String recommender) {
		this.recommender = recommender;
	}

	public int getPoint() {
		return point;
	}

	public void setPoint(int point) {
		this.point = point;
	}

	public Date getRegisterdate() {
		return registerdate;
	}

	public void setRegisterdate(Date registerdate) {
		this.registerdate = registerdate;
	}

	public Date getLatestdate() {
		return latestdate;
	}

	public void setLatestdate(Date latestdate) {
		this.latestdate = latestdate;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public int getIsonline() {
		return isonline;
	}

	public void setIsonline(int isonline) {
		this.isonline = isonline;
	}

	public Graderecord getGraderecord() {
		return graderecord;
	}

	public void setGraderecord(Graderecord graderecord) {
		this.graderecord = graderecord;
	}

	@Override
	public String toString() {
		return "Memberinfo [id=" + id + ", nickname=" + nickname
				+ ", password=" + password + ", gender=" + gender + ", age="
				+ age + ", email=" + email + ", provincecity=" + provincecity
				+ ", address=" + address + ", phone=" + phone
				+ ", passwordquestion=" + passwordquestion
				+ ", passwordanswer=" + passwordanswer + ", recommender="
				+ recommender + ", point=" + point + ", registerdate="
				+ registerdate + ", latestdate=" + latestdate + ", status="
				+ status + ", isonline=" + isonline + ", graderecord="
				+ graderecord + "]";
	}

}
package com.briup.bean;

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 = "graderecord")
public class Graderecord {
	@Id
	@SequenceGenerator(name="seq_type",sequenceName="SEQ_COMMON")
	@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="seq_type")
	private int id;
	private int min_point;
	private int max_point;
	private String gradename;
	private String iconpath;

	public Graderecord() {
		super();
		// TODO Auto-generated constructor stub
	}

	public Graderecord(int min_point, int max_point, String gradename,
			String iconpath) {
		super();
		this.min_point = min_point;
		this.max_point = max_point;
		this.gradename = gradename;
		this.iconpath = iconpath;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getMin_point() {
		return min_point;
	}

	public void setMin_point(int min_point) {
		this.min_point = min_point;
	}

	public int getMax_point() {
		return max_point;
	}

	public void setMax_point(int max_point) {
		this.max_point = max_point;
	}

	public String getGradename() {
		return gradename;
	}

	public void setGradename(String gradename) {
		this.gradename = gradename;
	}

	public String getIconpath() {
		return iconpath;
	}

	public void setIconpath(String iconpath) {
		this.iconpath = iconpath;
	}

	@Override
	public String toString() {
		return "Graderecord [id=" + id + ", min_point=" + min_point
				+ ", max_point=" + max_point + ", gradename=" + gradename
				+ ", iconpath=" + iconpath + "]";
	}

}
--创建会员表
create  table memberinfo (
	id number primary key,
	nickname varchar2(20) not null,
	password varchar2(50) not null,
	gender varchar2(1) not null,
	age number not null,
	email varchar2(100) not null,
	provincecity varchar2(10),
	address varchar2(200),
	phone varchar2(50),
	passwordquestion varchar2(200),
	passwordanswer varchar2(200),
	recommender varchar2(20),
	point number default 0,
	registerdate date,
	latestdate date,
	status number default 0,
	isonline number default 0,
	gradeid number,
	constraint info_grade foreign key(gradeid) references graderecord(id)
);

--创建等级表
create table graderecord(
	id number primary key,
	min_point number not null,
	max_point number not null,
	gradename varchar2(20) not null,
	iconpath varchar2(50) not null
);



你可能感兴趣的:(注解方式将java类与数据库表关联,包括序列自增长)