直接上源码:
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;
}
}
<?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);
}
}