hibernate转到sql2000的注意事项

开始时在pg8.3下开发,后将数据库迁移至sql2000,还是有点不顺利。
要注意下:
sql2000的自增长使用:numberic
 
 
查询类别最新:
 
@SuppressWarnings( "unchecked")    
    @Override    
     public List<IssueLog> listCurrentBoxState() {    

        String hql1 = "from Box as box";    

        List<Box> boxs = this.getHibernateTemplate().find(hql1);    
        List<IssueLog> issueLogs = new ArrayList<IssueLog>();    

         for ( final Box b : boxs) {    

             final String hql2 = "from IssueLog where box.id=? order by datetime desc";    

            issueLogs.addAll( this.getHibernateTemplate().executeFind( new HibernateCallback() {    

                 public Object doInHibernate(Session session) throws HibernateException, SQLException {    

                     return session.createQuery(hql2).setParameter(0, b.getId()).setMaxResults(1).list();    

                }    

            }));    

        }    

         return issueLogs;    
    }

 
 
对hibernate不是很熟,所以用了一个最笨的方法:遍历全部的box,根据boxid找到更新记录中的最新一条。
 
将pg迁移至sql2000,需要以下驱动:
jtds-1.2.2.jar;    
msutil.jar;    
mssqlserver.jar;    
mabase.jar
 
使用jtds的原因:当使用ms的驱动时,会抛出“can not re-read row data for column 1”的异常,google后改用第三方的驱动,即:jtds.jar;在sourceforge有下。
 
之后,配置文件修改为:
   < bean id ="dataSource" class ="org.apache.commons.dbcp.BasicDataSource" destroy-method ="close" >
     < property name ="driverClassName" value ="net.sourceforge.jtds.jdbc.Driver" />
     < property name ="url" value ="jdbc:jtds:sqlserver://localhost:1433;DatabaseName=new121" />
     < property name ="username" value ="root" />
     < property name ="password" value ="root />
     < property name ="maxActive" value ="30" />
     < property name ="maxIdle" value ="10" />
     < property name ="maxWait" value ="10" />
   </ bean >

   < bean id ="sessionFactory" class ="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
     < property name ="dataSource" ref ="dataSource" />
     < property name ="hibernateProperties" >
       < props >
         < prop key ="hibernate.dialect" >org.hibernate.dialect.SQLServerDialect </ prop >
         < prop key ="hibernate.show_sql" >true </ prop >
       </ props >
     </ property >

     < property name ="mappingResources" >
       < list >
         < value >Box.hbm.xml </ value >
         < value >User.hbm.xml </ value >
         < value >IssueLog.hbm.xml </ value >
       </ list >
     </ property >
   </ bean >
 
可顺利迁移。
 
发现这个网站的blog跨浏览器不是很好。

你可能感兴趣的:(数据库,Hibernate,职场,休闲)