这是我的model
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.ems.model.Institution" table="institution">
<id column="id" name="id" type="long">
<generator class="identity"/>
</id>
<property column="name" length="50" name="name" type="string"/>
<property column="reason" length="1000" name="reason" type="string"/>
<property column="explain" length="1000" name="explain" type="string"/>
<property column="createtime" length="23" name="createtime" type="timestamp"/>
</class>
</hibernate-mapping>package com.ems.model;import java.io.Serializable;
import java.util.Date;/** 奖惩 */
public class Institution implements Serializable { /** identifier field */
private Long id; /** nullable persistent field */
private String name; /** 原因 */
private String reason; /** 说明 */
private String explain; /** nullable persistent field */
private Date createtime; /** full constructor */
public Institution(String name, String reason, String explain, Date createtime) {
this.name = name;
this.reason = reason;
this.explain = explain;
this.createtime = createtime;
} /** default constructor */
public Institution() {
} public Long getId() {
return this.id;
} public void setId(Long id) {
this.id = id;
} public String getName() {
return this.name;
} public void setName(String name) {
this.name = name;
} public String getReason() {
return this.reason;
} public void setReason(String reason) {
this.reason = reason;
} public String getExplain() {
return this.explain;
} public void setExplain(String explain) {
this.explain = explain;
} public Date getCreatetime() {
return this.createtime;
} public void setCreatetime(Date createtime) {
this.createtime = createtime;
} public String toString() {
StringBuffer toStr = new StringBuffer();
toStr.append("[Institution] = [\n");
toStr.append(" id = " + this.id + ";\n");
toStr.append(" name = " + this.name + ";\n");
toStr.append(" reason = " + this.reason + ";\n");
toStr.append(" createtime = " + this.createtime+ ";\n");
toStr.append(" explain = " + this.explain + ";\n");
toStr.append(" ];\n");
return toStr.toString();
}}这是我的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"><!-- 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/ems</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="myeclipse.connection.profile">jdbcDriver</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<property name="current_session_context_class">thread</property>
<mapping resource="com/ems/model/Educate.hbm.xml"/>
<mapping resource="com/ems/model/Institution.hbm.xml"/>
<mapping resource="com/ems/model/Job.hbm.xml"/>
<mapping resource="com/ems/model/Stipend.hbm.xml"/>
<mapping resource="com/ems/model/Users.hbm.xml"/>
</session-factory></hibernate-configuration>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.ems.model.Institution" table="institution">
<id column="id" name="id" type="long">
<generator class="identity"/>
</id>
<property column="name" length="50" name="name" type="string"/>
<property column="reason" length="1000" name="reason" type="string"/>
<property column="explain" length="1000" name="explain" type="string"/>
<property column="createtime" length="23" name="createtime" type="timestamp"/>
</class>
</hibernate-mapping>package com.ems.model;import java.io.Serializable;
import java.util.Date;/** 奖惩 */
public class Institution implements Serializable { /** identifier field */
private Long id; /** nullable persistent field */
private String name; /** 原因 */
private String reason; /** 说明 */
private String explain; /** nullable persistent field */
private Date createtime; /** full constructor */
public Institution(String name, String reason, String explain, Date createtime) {
this.name = name;
this.reason = reason;
this.explain = explain;
this.createtime = createtime;
} /** default constructor */
public Institution() {
} public Long getId() {
return this.id;
} public void setId(Long id) {
this.id = id;
} public String getName() {
return this.name;
} public void setName(String name) {
this.name = name;
} public String getReason() {
return this.reason;
} public void setReason(String reason) {
this.reason = reason;
} public String getExplain() {
return this.explain;
} public void setExplain(String explain) {
this.explain = explain;
} public Date getCreatetime() {
return this.createtime;
} public void setCreatetime(Date createtime) {
this.createtime = createtime;
} public String toString() {
StringBuffer toStr = new StringBuffer();
toStr.append("[Institution] = [\n");
toStr.append(" id = " + this.id + ";\n");
toStr.append(" name = " + this.name + ";\n");
toStr.append(" reason = " + this.reason + ";\n");
toStr.append(" createtime = " + this.createtime+ ";\n");
toStr.append(" explain = " + this.explain + ";\n");
toStr.append(" ];\n");
return toStr.toString();
}}这是我的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"><!-- 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/ems</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="myeclipse.connection.profile">jdbcDriver</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<property name="current_session_context_class">thread</property>
<mapping resource="com/ems/model/Educate.hbm.xml"/>
<mapping resource="com/ems/model/Institution.hbm.xml"/>
<mapping resource="com/ems/model/Job.hbm.xml"/>
<mapping resource="com/ems/model/Stipend.hbm.xml"/>
<mapping resource="com/ems/model/Users.hbm.xml"/>
</session-factory></hibernate-configuration>
按道理来讲是应该可以自动生成数据库的,但我现在生成不了
我估计你是配置得不全。
如果单单用hibernate的话有一个ExportDb.java可以导出。