Hibernate入门学习(二):Hibernate所涉及的文件
HIbernate有这么几个主角:
pojo.java
pojo.hbm.xml
hibernate.cfg.xml(或hibernate.perperty)
pojo.java:这个类是个JavaBean。为什么要有个JavaBean呢?因为每个数据库的表必须有个和它对应的对象,这样Hibernate才能利用对象的属性把数据插入到数据库中。因此就必须每个数据库表对应一个,这个JavaBean就是pojo类。
实例UserInfo.java:
public class UserInfo { private Integer id; private String name; private String password;public Integer getId() {return id;}private void setId(Integer id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}}
<hibernate-mapping> <class name="com.dodo1988.UserInfo" table="users"> <id name="id" type="integer"> <column name="id" /> <generator type="string"> <column name="name" length="20" /> </property> <property name="password" type="string"> <column name="password" length="20" /> </property> </class></hibernate-mapping>
<session-factory><property name="connection.driver_class">com.mysql.jdbc.Driver</property><property name="connection.url">jdbc:mysql://localhost:3306/test</property><property name="dialect">org.hibernate.dialect.MySQLDialect</property><property name="connection.username">root</property><property name="connection.password">dodo</property><property name="show_sql">true</property><property name="connection.pool_size">15</property><mapping resource="Users.hbm.xml" /></session-factory>
hibernate.dialect org.hibernate.dialect.MySQLDialecthibernate.connection.driver_class com.mysql.jdbc.Driverhibernate.connection.url jdbc:mysql://localhost:3306/testhibernate.connection.username roothibernate.connection.password dodo