浏览 1773 次
该帖已经被评为隐藏帖
|
|
---|---|
作者 | 正文 |
发表时间:2008-04-28
这样来说吧,大家学习Hibernate 的时候肯定会对它的配置文件感到困惑,首先,我们一般需要一个Pojo类(即普通的java类) import java.io.Serializable; public class User implements Serializable { //标识属性 private int id; //用户名属性 private String userName; //密码属性 private String password; //电子邮件属性 private String email; public void setId(int id) { this.id = id; } public int getId() { return this.id; } public void setUserName(String user) { this.userName = user; } public String getUserName() { return this.userName; } public void setPassword(String pass) { this.password = pass; } public String getPassword() { return this.password; } public void setEmail(String email) { this.email = email; } public String getEmail() { return this.email; } } 然后,要实现ORM(Object Relational Mapping )需要一个 以 ".hbm.xml"后缀的映射文件,这样就可以实现对象映射关系.这里我的数据库使用的是Orale User.hbm.xml <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.chen.model"> <class name="User" table="user_table"> <id name="id" column="user_id"> <generator class="increment"/> </id> <property name="userName" column="user_name" not-null="true" length="100"/> <property name="password" not-null="true" length="100" column="user_pwd"/> <property name="email" column="user_mail" length="100"/> </class> </hibernate-mapping> 很自然的,要连接数据库,要一些数据库的配置 "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> <property name="show_sql">true</property> <!-- Drop and re-create the database schema on startup --> <property name="hbm2ddl.auto">update</property> <property name="connection.driver_class"> oracle.jdbc.driver.OracleDriver </property> <property name="connection.url"> jdbc:oracle:thin:@localhost:1521:ORA </property> <property name="connection.username">chenlei</property> <property name="connection.password"></property> <property name="dialect"> org.hibernate.dialect.Oracle9Dialect </property> <mapping resource="com/test/hbm/User.hbm.xml" /> </session-factory> </hibernate-configuration> 这样子基本的连接就OK 了,希望这些配置文件可以对初学者有帮助,请原谅我一开始的无知 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-04-29
你的帖子莫名其妙哦~~~
|
|
返回顶楼 | |