Hibernate Synchronizer
下载地址:
http://sourceforge.net/project/showfiles.php?group_id=99370

备份一下主键id映射:  
int          native           int primary key identity(1,1)
String    uuid.hex       varchar(n)/char(n) primary key
int          assigned       int primary key

//分页
Criteria criteria = session.createCriteria(Article.class);
criteria.setFirstResult(first);
criteria.setFetchSize(recordsNum);
//criteria.setMaxResults(recordsNum);
//分组和统计
criteria.setProjection(Projections.groupProperty("age"));
//多条件的分组统计
ProjectionList pList = Projections.projectionList();
pList.add(Projections.groupProperty("age"));
pList.add(Projections.rowCount());
criteria.setProjection(pList);
//排序
criteria.addOrder(Order.desc("id"));
criteria.addOrder(Order.asc("id"));

    Article article  =   new  Article();
    
//     article.setId(3);
        article.setTitle( " mytitle " );
        article.setContent(
" mycontent " );
        Configuration c 
=   new  Configuration();
        c.configure();
        SessionFactory sf 
=  c.buildSessionFactory();
        Session s 
=  sf.openSession();
        s.beginTransaction();
        s.save(article);
        s.flush();
        
try {
            s.connection().commit();
        }
catch (Exception e) {
            System.out.println(
" Exceptionee.. " );
        }

        s.close();

Resource ac  =   new  ClassPathResource( " /applicationContext.xml " );
        XmlBeanFactory xbf 
=   new  XmlBeanFactory(ac);
        IManagerArticleDao dao 
=  (IManagerArticleDao)xbf.getBean( " DAO " );
posted on 2006-06-19 08:13 pear 阅读(262) 评论(0)  编辑  收藏 所属分类: 技术

只有注册用户登录后才能发表评论。


网站导航: