Git Product home page Git Product logo

Comments (6)

diyhi avatar diyhi commented on July 17, 2024

用户注册扩展信息需要支持搜索,就只能用这种结构储存数据

from bbs.

vincenty1ung avatar vincenty1ung commented on July 17, 2024

你可以用list批量保存啊

from bbs.

diyhi avatar diyhi commented on July 17, 2024

JPA的保存接口只有em.persist(entity)这个吧,哪里支持List类型

from bbs.

vincenty1ung avatar vincenty1ung commented on July 17, 2024

我没有用过jpa规范下的数据层框架(hibernate,springboot jpa),还没有细看你的代码,不知道你这样循环调用save 每次的都是开启新的会话,去访问db,还是只有一个会话,如果是多个session不建议这样做,我用的比较low用mybatis,当出现批量操作时500size为一个阈值,也就是500数据集一个sql,500-1000第二个sql,不会出现for(sql执行ing)。

from bbs.

rabinchen avatar rabinchen commented on July 17, 2024

可以开启一个事务,批量插入吧

from bbs.

diyhi avatar diyhi commented on July 17, 2024

在同一事务里循环提交最后是批量插入的

例如JPA插入日志里显示
insert into t1 (f1, f2, f3) values (?, ?, ?) insert into t1 (f1, f2, f3) values (?, ?, ?) insert into t1 (f1, f2, f3) values (?, ?, ?)

实际上查看MySQL的日志记录查询执行日志显示
2020-04-24T05:06:48.103800Z 99 Query insert into t1 (f1, f2, f3) values ('a1', 'b1', 'c1'),('a2', 'b2', 'c2'),('a3', 'b3', 'c3')

主要是这两个配置起了作用:
persistence.xml文件的
<property name="hibernate.jdbc.batch_size" value="10"/>

druid.properties文件的
rewriteBatchedStatements=true

设置以上参数后,MySQL驱动会将插入语句重新组合再提交

附开启MySQL日志方法

MySQL查询日志功能是否开启
SHOW VARIABLES LIKE 'general%';

general_log:日志功能是否开启,默认关闭OFF
general_log_file:日志文件保存位置

开启日志
set GLOBAL general_log='ON';

查询是否开启
SHOW VARIABLES LIKE 'general_log';

重启MySQL服务后需要重新配置

`mysql> SHOW VARIABLES LIKE 'general%';
+------------------+-------------------------+
| Variable_name | Value |
+------------------+-------------------------+
| general_log | OFF |
| general_log_file | /var/lib/mysql/test.log |
+------------------+-------------------------+
2 rows in set (0.01 sec)

mysql> set GLOBAL general_log='ON';
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW VARIABLES LIKE 'general_log';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| general_log | ON |
+---------------+-------+
1 row in set (0.01 sec)`

from bbs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.