龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > JAVA开发 >

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

时间:2009-12-23 15:42来源:未知 作者:admin 点击:
分享到:
开发工具采用MYECLIPS3.6,首先是建立项目,导入STRUTS+HIBERNATE包,然后配置SRC跟目录下的hibernate.cfg.XML.我采用的是mysql数据库,所以配置如下: <hibernate-configuration> <session-factory> <!
 开发工具采用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
  
  
精彩图集

赞助商链接