Hibernate 实体类

Movie

package bean;

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

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
/**
 * Movie 实体类及注解
 * */
//多对一
@Entity
@Table
public class Movie {
	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="seq_movie")
	@SequenceGenerator(sequenceName="seq_movie",name="seq_movie",initialValue=1,allocationSize=1)
	private int id;//编号
	@Column
	private String titile;//电影名称
	@Column
	private String director;//导演
	@Column
	private String actor;//主演
	@Column
	private Double price;//价格
	@ManyToOne
	@Cascade(CascadeType.SAVE_UPDATE)
	@JoinColumn(name="typeid")
	private Type   type;//类型
	
	/*
	 * 构造方法
	 * */
	public Movie() {
	}
	public Movie(String titile, String director, String actor, Double price) {
		this.titile = titile;
		this.director = director;
		this.actor = actor;
		this.price = price;
	}
	
	public Movie(String titile, String director, String actor, Double price,
			Type type) {
		this.titile = titile;
		this.director = director;
		this.actor = actor;
		this.price = price;
		this.type = type;
	}
	/*
	 * 封装方法
	 * */
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getTitile() {
		return titile;
	}
	public void setTitile(String titile) {
		this.titile = titile;
	}
	public String getDirector() {
		return director;
	}
	public void setDirector(String director) {
		this.director = director;
	}
	public String getActor() {
		return actor;
	}
	public void setActor(String actor) {
		this.actor = actor;
	}
	public Double getPrice() {
		return price;
	}
	public void setPrice(Double price) {
		this.price = price;
	}
	public Type getType() {
		return type;
	}
	public void setType(Type type) {
		this.type = type;
	}
}

 

MovieCondition

package bean;
/**
 * 以Movie 实体类为条件
 * */
public class MovieCondition {
	
	private String titile;//电影名称
	private String director;//导演
	private String actor;;//主演
	private Double minPrice;//最小价格
	private Double maxPrice;//最大价格
	private Type   type;//电影类型
	
	/*
	 * 构造方法
	 * */
	public MovieCondition() {
	}
	public MovieCondition(String titile, String director, String actor,
			Double minPrice, Double maxPrice, Type type) {
		this.titile = titile;
		this.director = director;
		this.actor = actor;
		this.minPrice = minPrice;
		this.maxPrice = maxPrice;
		this.type = type;
	}
	/*
	 * 封装方法
	 * */
	public String getTitile() {
		return titile;
	}
	public void setTitile(String titile) {
		this.titile = titile;
	}
	public String getDirector() {
		return director;
	}
	public void setDirector(String director) {
		this.director = director;
	}
	public String getActor() {
		return actor;
	}
	public void setActor(String actor) {
		this.actor = actor;
	}
	public Double getMinPrice() {
		return minPrice;
	}
	public void setMinPrice(Double minPrice) {
		this.minPrice = minPrice;
	}
	public Double getMaxPrice() {
		return maxPrice;
	}
	public void setMaxPrice(Double maxPrice) {
		this.maxPrice = maxPrice;
	}
	public Type getType() {
		return type;
	}
	public void setType(Type type) {
		this.type = type;
	}
}

 

Type

package bean;

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;
/**
 * Type 实体类及注解
 * */
@Entity
@Table
public class Type {
	@Id
	@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="seq_type")
	@SequenceGenerator(sequenceName="seq_type",name="seq_type",initialValue=1,allocationSize=1)
	private int id;//类型编号
	@Column
	private String name;//类型名称
	
	/*
	 * 构造方法
	 * */
	public Type() {
	}
	public Type(String name) {
		this.name = name;
	}

	/*
	 * 封装方法
	 * */
	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;
	}
}

 

 

你可能感兴趣的:(Hibernate)