Hibernate 批理更新,删除,插入

    技术2022-05-11  82

    在hibernate 2时.一些批量的sql 操作,经常产生性能影响如删除100000个.在内存中加载如此多的对像是没有必要,所以我们的解决方法就是在hibernate中直接用JDBC 操作

    session.connection();

    Statment st=connection.createSatement().....等直接JDBC操作解决性能问题.

    现在hibnate中可能直接用HQL 进行批量操作,性能和用JDBC操作一样,

    如String hql="delete  news" 

    String hql="update news n  where n.newsId<10000";

    Query query=session.createQuery(hql);

    int size=query.executeUpdate()就行了..

     

     


    最新回复(0)