资讯   |   开发   |   选机中心   |   产品大全 | IBM | 惠普 | 联想 | 戴尔 | 苹果 | 神舟
更多: | 华硕 | 明基 | 方正 | 紫光 | TCL | 夏新 | 联宝 | 宏碁 | 七喜 | 长城 | 清华同方 | 海尔 | 三星 | 东芝 | 索尼 | 富士通 | LG | 技术 | ddnoon
当前位置:笔记本 > 软件开发 >
Advertisement
文章正文

Hibernate Cat之体验不成

类型:转载   责任编辑:asp.net   日期:2007/05/23


热门软件下载:


   

体验(1)  
  hibernate-cfg.xml  
  <?xml   version=1.0   encoding=UTF-8?>  
  <!DOCTYPE   hibernate-configuration   PUBLIC   "-//Hibernate/Hibernate   Configuration   DTD//EN"   "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">  
   
  <hibernate-configuration>  
   
          <session-factory>  
   
                  <property   name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>  
                  <property   name="connection.driver_class">com.mysql.jdbc.Driver</property>  
                  <property   name="connection.username">root</property>  
                  <property   name="connection.password"></property>  
                  <property   name="connection.url">jdbc:mysql://localhost:3306/test</property>  
                   
  <property   name="connection.pool.size">1</property>  
  <property   name="statement_cache.size">25</property>  
  <property   name="jdbc.fetch_size">50</property>  
  <property   name="jdbc.batch_size">30</property>  
   
  <property   name="show_sql">true</property>  
   
                  <!--   Mapping   files   -->  
                  <mapping   resource="com.lontu.struts.cat.hbm.xml"/>  
   
          </session-factory>  
   
  </hibernate-configuration>  
   
  cat.hbm.xml  
   
  <?xml   version="1.0"?>  
  <!DOCTYPE   hibernate-mapping  
          PUBLIC   "-//Hibernate/Hibernate   Mapping   DTD//EN"  
          "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">  
   
  <hibernate-mapping>  
   
          <class   name="net.sf.hibernate.examples.quickstart.Cat"   table="CAT">  
   
                  <!--   A   32   hex   character   is   our   surrogate   key.   Its   automatically  
                          generated   by   Hibernate   with   the   UUID   pattern.   -->  
                  <id   name="id"   type="string"   unsaved-value="null"   >  
                          <column   name="CAT_ID"   sql-type="char(32)"   not-null="true"/>  
                          <generator   class="uuid.hex"/>  
                  </id>  
   
                  <!--   A   cat   has   to   have   a   name,   but   it   shouldn   be   too   long.   -->  
                  <property   name="name">  
                          <column   name="NAME"   sql-type="varchar(16)"   not-null="true"/>  
                  </property>  
   
          </class>  
   
  </hibernate-mapping>  
   
  test.jsp  
   
  Session   ses   =   HibernateUtil.currentSession();  
  Transaction   tx   =   ses.beginTransaction();  
   
  Cat   pricess   =   new   Cat();  
   
  pricess.setId("1002");  
  pricess.setName("Cat");  
  ses.save(pricess);  
  tx.commit();  
  HibernateUtil.closeSession();  
 

网友回答:

发表者:zhigangsun

你是用strtus和hibernate结合的。HibernateUtil类里的初始化方法有问题吧,HibernateUtil.java32行看看是什么代码贴出来。

发表者:Henu

hibernate.cfg.xml  
  Cat.hbm.xml  
  放的路径对吗?


 

 
热门推荐笔记本: IBM笔记本
相关文章:
webmaster:popbb@126.com   最佳浏览:1024X768 MSIE
©2007 popbb.net All Rights Reserved