@注解_唯一约束

直接上代码咯

package cn.jbit.test2.bean;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

@Entity
@Table(name = "TBL_FLIGHT", uniqueConstraints = @UniqueConstraint(name = "flight_number", columnNames = {
		"comp_prefix", "flight_number" }))
public class Flight implements Serializable {
	
	private static final long serialVersionUID = -2329039752473928764L;
	
	@Id
	@GeneratedValue
	private Integer id;

	@Column(name = "comp_prefix")
	private String comp_prefix;

	@Column(name = "flight_number")
	private String flight_number;
	
	public Flight() {
		super();
	}

	public Flight(Integer id, String compPrefix, String flightNumber) {
		super();
		this.id = id;
		comp_prefix = compPrefix;
		flight_number = flightNumber;
	}

	public Integer getId() {
		return id;
	}

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

	public String getComp_prefix() {
		return comp_prefix;
	}

	public void setComp_prefix(String compPrefix) {
		comp_prefix = compPrefix;
	}

	public String getFlight_number() {
		return flight_number;
	}

	public void setFlight_number(String flightNumber) {
		flight_number = flightNumber;
	}
}

你可能感兴趣的:(Hibernate)