日期:2014-05-16  浏览次数:20416 次

注释方式 类生成数据库表
类对象:
package com.pojos;

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

/**
 * 
 * @author Administrator
 *
 */
@Entity
@Table(name="sxy_QNEPassenger")
public class QNEPassenger {

	@Id
	@GeneratedValue
	private long id;				//ID
	
	@Column(length=30,nullable=false)
	private String name;			//姓名
	
	@Column(length=30,nullable=false)
	private int sex;				//性别
	
	@Column(length=30,nullable=false)
	private int type;				//类型
	
	@Column(length=30,nullable=false)
	private String birthDay;		//生日
	
	@Column(length=30,nullable=false)
	private String ticketNum;		//票号
	
	@Column(length=30,nullable=false)
	private String insuranceStatus; //保险状态
	
	private float insurancePrice;	//保险价格
	
	@Column(length=30,nullable=false)
	private String insuranceNum;	//保单号
	
	@ManyToOne
	private QNEOrder order;			//订单
	
	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;
	}
	public int getSex() {
		return sex;
	}
	public void setSex(int sex) {
		this.sex = sex;
	}
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
	public String getBirthDay() {
		return birthDay;
	}
	public void setBirthDay(String birthDay) {
		this.birthDay = birthDay;
	}
	public String getTicketNum() {
		return ticketNum;
	}
	public void setTicketNum(String ticketNum) {
		this.ticketNum = ticketNum;
	}
	public String getInsuranceStatus() {
		return insuranceStatus;
	}
	public void setInsuranceStatus(String insuranceStatus) {
		this.insuranceStatus = insuranceStatus;
	}
	public float getInsurancePrice() {
		return insurancePrice;
	}
	public void setInsurancePrice(float insurancePrice) {
		this.insurancePrice = insurancePrice;
	}
	public String getInsuranceNum() {
		return insuranceNum;
	}
	public void setInsuranceNum(String insuranceNum) {
		this.insuranceNum = insuranceNum;
	}
	public QNEOrder getOrder() {
		return order;
	}
	public void setOrder(QNEOrder order) {
		this.order = order;
	}
	
	/******其它信息*******/
}




在hibernate 配置文件中添加你的类对象
引用


   <?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

    <session-factory>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/ajaxtest</property>
        <property name="connection.username">root</property>
        <property name="connection.password">admin</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="myeclipse.connection.profile">mysql</property>
       
   <mapping class="com.pojos.QNEOrder"/>
    <mapping class="com.pojos.QNEPassenger"/>
<