Это мой код для вставки партии в базе данныхHibernate партии вставить
@Override
public void addMultiple(){
session = get_session();
tx = session.beginTransaction();
for (int i=0; i<100; i++) {
Person person = new Person();
person.setName("oll"+i);
session.save(person);
if(i % 20 == 0) { // Same as the JDBC batch size
//flush a batch of inserts and release memory:
session.flush();
session.clear();
}
}
tx.commit();
session.close();
}
это мой hibernate.cfg.xml
файл
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test?rewriteBatchedStatements=true</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.show_sql">true</property>
<property name="format_sql">true</property>
<property name="hibernate.jdbc.batch_versioned_data">true</property>
<property name="hibernate.jdbc.batch_size">20</property>
<property name="hibernate.order_inserts">true</property>
<property name="hibernate.current_session_context_class">thread</property>
но после операции вставки я могу увидеть запрос печатается в консоли
Hibernate: insert into Person (name) values (?)
Hibernate: insert into Person (name) values (?)
Hibernate: insert into Person (name) values (?)
Hibernate: insert into Person (name) values (?)
Hibernate: insert into Person (name) values (?)
Hibernate: insert into Person (name) values (?)
Hibernate: insert into Person (name) values (?)
Hibernate: insert into Person (name) values (?)
Hibernate: insert into Person (name) values (?)
Hibernate: insert into Person (name) values (?)
Hibernate: insert into Person (name) values (?)
Это означает, что он не вставляет партии. У моего объекта нет генерации идентификатора. Так в чем проблема? Почему я не могу вставить пакет?
Мой Entity класса являются
@Entity
public class Person {
@Id
public String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
См. Мой отредактированный ответ. Вы пытались использовать параметр 'profileSQL', чтобы проверить, перезаписывает ли драйвер MySQL? –