NutzCN Logo
问答 多线程并发数据插入时,hash值计算异常的问题
发布于 2727天前 作者 qq_ef6310b4 1791 次浏览 复制 上一个帖子 下一个帖子
标签:

以下异常是在大量数据并发插入数据库的时候,报的错,求解释啊

2017-07-05 21:44:51,246 [ERROR] [HashThread-pool-6-thread-1] MessageFacadeInvoker.handleExeception - org.nutz.dao.DaoException: org.nutz.dao.DaoException: !Nutz SQL Error: 'INSERT INTO string(hash) VALUES(?) 
    |           1 |
    |-------------|
    | -1507525949 |
  For example:> "INSERT INTO string(hash) VALUES(-1507525949) "'
PreparedStatement: 
'INSERT INTO string(hash) VALUES(?) '
10 回复

完整报错信息

你这个 hash 是咋算的?

来自美丽的 NutzCN

不是我算的啊,好像是nutz dao自动算的

21:38:29,482 [ERROR] [HashThread-pool-1-thread-1] MessageFacadeInvoker.handleExeception - 执行330协议出现异常
21:38:29,482 [ERROR] [HashThread-pool-1-thread-1] MessageFacadeInvoker.handleExeception - org.nutz.dao.DaoException: org.nutz.dao.DaoException: !Nutz SQL Error: 'INSERT INTO string(hash) VALUES(?) 
    |          1 |
    |------------|
    | 1137543928 |
  For example:> "INSERT INTO string(hash) VALUES(1137543928) "'
PreparedStatement: 
'INSERT INTO string(hash) VALUES(?) '
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.xiuxian.core.framework.CallBack.handle(CallBack.java:19)
	at com.xiuxian.core.msg.MessageFacadeInvoker.handleMessage(MessageFacadeInvoker.java:45)
	at com.xiuxian.core.msg.MessageFacadeInvoker.run(MessageFacadeInvoker.java:26)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.nutz.dao.DaoException: org.nutz.dao.DaoException: !Nutz SQL Error: 'INSERT INTO string(hash) VALUES(?) 
    |          1 |
    |------------|
    | 1137543928 |
  For example:> "INSERT INTO string(hash) VALUES(1137543928) "'
PreparedStatement: 
'INSERT INTO string(hash) VALUES(?) '
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:76)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:204)
	at org.nutz.dao.impl.EntityOperator.exec(EntityOperator.java:50)
	at org.nutz.dao.impl.NutDao.insert(NutDao.java:138)
	at com.xiuxian.module.friend.dao.FriendDao.add(FriendDao.java:32)
	at com.xiuxian.module.friend.dao.FriendDao.add(FriendDao.java:1)
	at com.xiuxian.core.cache.CacheMap.putWithCache(CacheMap.java:105)
	at com.xiuxian.module.friend.dao.FriendManager.getFriendGroup(FriendManager.java:47)
	at com.xiuxian.module.friend.FriendSystem.getFriendGroup(FriendSystem.java:80)
	at com.xiuxian.module.friend.FriendSystem.loadFriendList(FriendSystem.java:89)
	at com.xiuxian.module.friend.FriendFacade.loadFriendList(FriendFacade.java:30)
	... 12 more
Caused by: org.nutz.dao.DaoException: !Nutz SQL Error: 'INSERT INTO string(hash) VALUES(?) 
    |          1 |
    |------------|
    | 1137543928 |
  For example:> "INSERT INTO string(hash) VALUES(1137543928) "'
PreparedStatement: 
'INSERT INTO string(hash) VALUES(?) '
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:90)
	at org.nutz.dao.impl.DaoSupport$DaoExec.invoke(DaoSupport.java:249)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:64)
	... 22 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'xiuxian.string' doesn't exist
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
	at com.mysql.jdbc.Util.getInstance(Util.java:384)
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4232)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4164)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2838)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
	at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1307)
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:2931)
	at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440)
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:2929)
	at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:118)
	at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:493)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor._runPreparedStatement(NutDaoExecutor.java:261)
	at org.nutz.dao.impl.sql.run.NutDaoExecutor.exec(NutDaoExecutor.java:76)
	... 24 more

nutz没有内置这种功能,另外,是不是key重复了,这种hash太容易重复了

额,我的这个table设置的是默认自增,就是说,多并发的情况下,不能默认自增的是吧?

@Table("req_record")
public class RequestRecord {
    @Id
    private int id; // 默认自增
    @Column
    private Date reqTime;
    @Column
    private Date respTime;
    @Column
    private String roldId;
    @Column
    private int protoId;
    @Column
    private long doTime;

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'xiuxian.string' doesn't exis
不是表不存在吗?

不是的,根本没有这个表,我操作的表是“req_record”

看来是FriendDao写错东西了呢,把字符串当pojo插入了

把FriendDao的代码贴来看看

是的是的,firendDao中吧字符串当做pojo插入了,问题解决了,感谢wendal大哥!太厉害了!

添加回复
请先登陆
回到顶部