利用开源项目Hibernate开发Blog系统
2008-01-05 20:31:13 来源:WEB开发网核心提示:开发工具采用MYECLipS3.6,首先是建立项目,导入STRUTS+HIBERNATE包,利用开源项目Hibernate开发Blog系统,然后配置SRC跟目录下的hibernate.cfg.xml.我采用的是MySQL数据库,所以配置如下:<hibernate-configuration> <session-f
开发工具采用MYECLipS3.6,首先是建立项目,导入STRUTS+HIBERNATE包,然后配置SRC跟目录下的hibernate.cfg.xml.我采用的是MySQL数据库,所以配置如下:
下面我们继续HIBERNATE程序的下步编写
<hibernate-configuration>mapping为javaBEAN所对应的映射。
<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>
下面我们继续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
更多精彩
赞助商链接