`
yzz9i
  • 浏览: 216812 次
  • 性别: Icon_minigender_1
  • 来自: 湖南
社区版块
存档分类
最新评论

注释方式 类生成数据库表

阅读更多
类对象:
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"/>

    </session-factory>

</hibernate-configuration>

applicationContext.xml 配置文件中:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:annotation-config />
<context:component-scan base-package="com.pojos" />

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>

</beans>

引用




测试方法:
引用

public class Test1 {

@Test
public void test1() {
Configuration conf=new AnnotationConfiguration().configure();
SchemaExport se=new SchemaExport(conf);
se.create(true, true);
}
}



okl   http://yzz9i.iteye.com/blog/1052036


0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics