hibernate @table

@javax.persistence.Table(catalog=”xx”,name=”xx”,schema=”xx”,uniqueConstraints={ @UniqueConstraint(columnNames={“xx”,”xx”})})
name:指定表的名称
catalog:指定数据库名称
schema:指定数据库的用户名
uniqueConstraints:指定唯一性字段约束,如为personid 和name 字段指定唯一性约束
uniqueConstraints={ @UniqueConstraint(name=”xxx” columnNames={“personid”, “name”})}
@UniqueConstraint 中的name=”xxx”为唯一约束名,代码如下:
package com.cmh.beans;

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 @table)