利用开源项目Hibernate开发Blog系统

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

开发工具采用MYECLIPS3.6,首先是建立项目,导入STRUTS+HIBERNATE包,然后配置SRC跟目录下的hibernate.cfg.XML.我采用的是mysql数据库,所以配置如下:

<hibernate-configuration>

<session-factory>

<!-- properties -->

<property name="connection.username">root</property>

<property name="connection.url">jdbc:mysql://localhost:3306/tonnyblog</property>

<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>

<property name="connection.passWord"></property>

<property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>

<!-- mapping files -->

<mapping resource="com/tonny/blog/bean/User.hbm.xml"/>

<mapping resource="com/tonny/blog/bean/Item.hbm.xml"/>

<mapping resource="com/tonny/blog/bean/Review.hbm.xml"/>

</session-factory>

</hibernate-configuration>

mapping为JavaBEAN所对应的映射。

下面我们继续HIBERNATE程序的下步编写

import net.sf.hibernate.HibernateException;

import net.sf.hibernate.Session;

import net.sf.hibernate.SessionFactory;

import net.sf.hibernate.cfg.Configuration;

/**

* Description of the Class

*

* @author tonny

* @created 2004年2月6日

*/

public class HibernateUtil {

private final static SessionFactory sessionFactory;

static {

try {

sessionFactory =

new Configuration().configure().buildSessionFactory();

} catch (HibernateException ex) {

throw new RuntimeException(

"Exception building SessionFactory: " + ex.getMessage(),ex);

}

}

private HibernateUtil(){

}

/**

* Description of the Field

*/

private final static ThreadLocal session = new ThreadLocal();

/**

* Description of the Method

*

* @return Description of the Return Value

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航