<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- 配置连接数据库的基本信息 --> <property name="connection.username">root</property> <property name="connection.password">123456</property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql:///hibernate</property> <!-- 配置 Hibernate 的基本信息 --> <property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property> <property name="show_sql">true</property> <property name="format_sql">true</property> <!-- 指定自动生成数据表的策略 --> <property name="hbm2ddl.auto">update</property> </session-factory> </hibernate-configuration>
(3)点击 Persistance 视图(View-ToolWindow-Persistance 或 直接点击快捷方式)
如果没有已经创建的 data source ,可以通过点击标红的按钮进行添加。如:
在不勾选 JPA Annotations 的情况下,生成的实体不含 JPA 注解。如:
/** * @author solverpeng * @create 2016-09-28-14:11 */ public class NewsEntity { private int id; private String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public boolean equals(Object o) { if(this == o) { return true; } if(o == null || getClass() != o.getClass()) { return false; } NewsEntity that = (NewsEntity) o; if(id != that.id) { return false; } if(name != null ? !name.equals(that.name) : that.name != null) { return false; } return true; } @Override public int hashCode() { int result = id; result = 31 * result + (name != null ? name.hashCode() : 0); return result; } }
NewsEntity.Java对应的 NewsEntity.hbm.xml 文件