注释方式 类生成数据库表

类对象:

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 配置文件中添加你的类对象
[quote]

<?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>

[b][color=red] <mapping class="com.pojos.QNEOrder"/>
<mapping class="com.pojos.QNEPassenger"/>[/color][/b]
</session-factory>

</hibernate-configuration>

applicationContext.xml 配置文件中:
[/quote]
<?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 />
[b][color=red]<context:component-scan base-package="com.pojos" />[/color][/b]

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

</beans>

[quote]

[/quote]

测试方法:
[quote]
public class Test1 {

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

[/quote]

okl [url]http://yzz9i.iteye.com/blog/1052036[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值