hibernate注解反向生成表结构

20 篇文章 0 订阅
10 篇文章 0 订阅

直接上源码:


package com.gxy.pojo.model;

import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * CstActivity entity
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "CST_ACTIVITY")
public class CstActivity implements java.io.Serializable {


	private Long atvId;
	private String atvCustNo;
	private Date atvDate;
	private String atvPlace;
	private String atvTitle;
	private String atvDesc;

	public CstActivity() {
	}

	public CstActivity(Long atvId, String atvCustNo, Date atvDate,
			String atvPlace, String atvTitle) {
		this.atvId = atvId;
		this.atvCustNo = atvCustNo;
		this.atvDate = atvDate;
		this.atvPlace = atvPlace;
		this.atvTitle = atvTitle;
	}

	public CstActivity(Long atvId, String atvCustNo, Date atvDate,
			String atvPlace, String atvTitle, String atvDesc) {
		this.atvId = atvId;
		this.atvCustNo = atvCustNo;
		this.atvDate = atvDate;
		this.atvPlace = atvPlace;
		this.atvTitle = atvTitle;
		this.atvDesc = atvDesc;
	}

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name = "ATV_ID", unique = true, nullable = false)
	public Long getAtvId() {
		return this.atvId;
	}

	public void setAtvId(Long atvId) {
		this.atvId = atvId;
	}

	@Column(name = "ATV_CUST_NO", nullable = false, length = 17)
	public String getAtvCustNo() {
		return this.atvCustNo;
	}

	public void setAtvCustNo(String atvCustNo) {
		this.atvCustNo = atvCustNo;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "ATV_DATE", nullable = false, length = 7)
	public Date getAtvDate() {
		return this.atvDate;
	}

	public void setAtvDate(Date atvDate) {
		this.atvDate = atvDate;
	}

	@Column(name = "ATV_PLACE", nullable = false, length = 200)
	public String getAtvPlace() {
		return this.atvPlace;
	}

	public void setAtvPlace(String atvPlace) {
		this.atvPlace = atvPlace;
	}

	@Column(name = "ATV_TITLE", nullable = false, length = 500)
	public String getAtvTitle() {
		return this.atvTitle;
	}

	public void setAtvTitle(String atvTitle) {
		this.atvTitle = atvTitle;
	}

	@Column(name = "ATV_DESC", length = 2000)
	public String getAtvDesc() {
		return this.atvDesc;
	}

	public void setAtvDesc(String atvDesc) {
		this.atvDesc = atvDesc;
	}

}


hibernate.cfg.xml配置文件如下:
<?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">
<hibernate-configuration>
	<session-factory>
		<!-- dialect指定数据库使用的方言 -->
		<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
		<!-- connection.dirver_class指定数据库的驱动程序 -->
		<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
		<!-- connection.url指定连接数据库的URL -->
		<property name="connection.url">jdbc:sqlserver://192.168.0.212:8763;DatabaseName=cmbpojo</property>
		<!-- connection.username指定连接数据库的用户名 -->
		<property name="connection.username">sa</property>
		<!-- connection.password指定连接数据库的密码 -->
		<property name="connection.password">123</property>
		<!-- show_sql指定是否打印SQL语句 -->
		<property name="show_sql">true</property>
		
		
		<mapping class="com.gxy.pojo.model.CstActivity"/>
		 
	</session-factory>
</hibernate-configuration>

test 测试类:

package com.gxy.test;

import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class POJOTest {

	public static void main(String[] args) {
		Configuration config = new AnnotationConfiguration().configure(); 
		SchemaExport schemaExport = new SchemaExport(config); 
		schemaExport.create(true, true);
	}
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值