Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate批处理插入1000000条记录_Java_Hibernate_Batch Processing - Fatal编程技术网

Java Hibernate批处理插入1000000条记录

Java Hibernate批处理插入1000000条记录,java,hibernate,batch-processing,Java,Hibernate,Batch Processing,当我试图在MySQL数据库中插入1000000条记录时,实际上只有1000条。怎么了 这是我的hibernate.cfg.xml com.mysql.jdbc.Driver jdbc:mysql://localhost:3307/hibernatedb 根 贝尔沃13 一, 五十 org.hibernate.dialogue.mysqldialogue 线 org.hibernate.cache.NoCacheProvider--> 假 org.hibernate.cache.E

当我试图在MySQL数据库中插入1000000条记录时,实际上只有1000条。怎么了

  • 这是我的hibernate.cfg.xml

    com.mysql.jdbc.Driver jdbc:mysql://localhost:3307/hibernatedb 根 贝尔沃13

    一,

    五十

    org.hibernate.dialogue.mysqldialogue

    线

    org.hibernate.cache.NoCacheProvider-->



    org.hibernate.cache.EhCacheProvider

    真的

    更新

  • 这是我的学生:

    package ua.berchik.vovchuk.dto;
    
    导入java.io.Serializable

    导入javax.persistence.Cacheable; 导入javax.persistence.Column; 导入javax.persistence.Entity; 导入javax.persistence.GeneratedValue; 导入javax.persistence.GenerationType; 导入javax.persistence.Id; 导入javax.persistence.Table

    导入org.hibernate.annotations.Cache; 导入org.hibernate.annotations.cacheconcurrency策略

    @可缓存的
    @缓存(用法=缓存并发策略。只读) @实体 @表(name=“STUDENT”) 公共类学生实现可序列化{

    private static final long serialVersionUID = -6853928080190944025L;
    
    @Id
    @Column(name="ID")
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;
    @Column(name="STUDENT_NAME")
    private String studName;
    @Column(name="ROLE_NUMBER")
    private int rollNumb;
    @Column(name="COURSE")
    private String course;
    
    public Student(){}
    
    public Student(String studName, int rollNumb, String course) {
        super();
        this.studName = studName;
        this.rollNumb = rollNumb;
        this.course = course;
    }
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getStudName() {
        return studName;
    }
    public void setStudName(String studName) {
        this.studName = studName;
    }
    public int getRollNumb() {
        return rollNumb;
    }
    public void setRollNumb(int rollNumb) {
        this.rollNumb = rollNumb;
    }
    public String getCourse() {
        return course;
    }
    public void setCourse(String course) {
        this.course = course;
    }
    
    public String toString()  
     {  
      return "Id: "+this.id+" ROLL Number: "+this.rollNumb+"| Name: "+this.studName+"| Course: "+this.course;  
     } 
    
    }

  • 这是我的冬眠:

    package ua.berchik.vovchuk.hibernate.util;
    
    导入org.hibernate.SessionFactory; 导入org.hibernate.annotations.common.annotationfactory.annotationfactory; 导入org.hibernate.cfg.AnnotationConfiguration

    公共类HibernateUtil{

    private static final SessionFactory sessionFactory;
    
    static{
        try{
            sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
        } catch(Throwable th){
            System.err.println("Initial SessionFactory creation failed"+th);
            throw new ExceptionInInitializerError(th);
        }
    }
    
    public static SessionFactory getSessionFactory(){
        return sessionFactory;
    }
    
    }

  • 这是我的主要观点:

    包ua.berchik.vovchuk.hibernate

    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import javax.xml.crypto.Data;
    
    import org.hibernate.Criteria;
    import org.hibernate.Query;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;
    import org.hibernate.criterion.Restrictions;
    
    import ua.berchik.vovchuk.dto.FourWheeler;
    import ua.berchik.vovchuk.dto.Student;
    import ua.berchik.vovchuk.dto.TwoWheeler;
    import ua.berchik.vovchuk.dto.User;
    import ua.berchik.vovchuk.dto.UserDetails;
    import ua.berchik.vovchuk.dto.Vehicle;
    import ua.berchik.vovchuk.hibernate.util.HibernateUtil;
    
    public class HiernateTest {
    
        public static void main(String[] args) {
    
            SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
            Session session = sessionFactory.openSession();
            session.beginTransaction();
    
            for ( int i=0; i<1000000; i++ )  
            {  
                Student student = new Student("Name "+i, i, "Course "+i);  
                session.save(student); 
                if(i%50 == 0){
                    session.flush();
                    session.clear();
                }
            }  
    
            session.getTransaction().commit();
            session.close();
        }
    
    }
    
    import java.util.HashMap;
    导入java.util.List;
    导入java.util.Map;
    导入javax.xml.crypto.Data;
    导入org.hibernate.Criteria;
    导入org.hibernate.Query;
    导入org.hibernate.Session;
    导入org.hibernate.SessionFactory;
    导入org.hibernate.cfg.Configuration;
    导入org.hibernate.criteria.Restrictions;
    进口ua.berchik.vovchuk.dto.FourWheeler;
    输入ua.berchik.vovchuk.dto.Student;
    进口ua.berchik.vovchuk.dto.TwoWheeler;
    导入ua.berchik.vovchuk.dto.User;
    导入ua.berchik.vovchuk.dto.UserDetails;
    进口ua.berchik.vovchuk.dto.车辆;
    导入ua.berchik.vovchuk.hibernate.util.HibernateUtil;
    公共类层次测试{
    公共静态void main(字符串[]args){
    SessionFactory SessionFactory=HibernateUtil.getSessionFactory();
    Session Session=sessionFactory.openSession();
    session.beginTransaction();
    对于(int i=0;i