mybatis generator自动生成代码报The error occurred while processing mapper_resultMap[BaseResultMap]错误的解决方法

今天在用mybatis自动生成代码之后遇到了一个错误:

org.apache.ibatis.exceptions.PersistenceException :
### Error building SqlSession.
### The error may exist in com/erp/webservice/mapper/UsersMapper.xml
### The error occurred while processing mapper_resultMap[BaseResultMap]
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.RuntimeException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException : Result Maps collection already contains value for com.erp.webservice.inter.UsersMapper.BaseResultMap
     at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
     at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:51)
     at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:35)
     at com.erp.webservice.test.Test.<clinit>( Test.java:22)
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.RuntimeException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException : Result Maps collection already contains value for com.erp.webservice.inter.UsersMapper.BaseResultMap
     at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:107)
     at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:89)
     at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:49)
     ... 2 more
Caused by: java.lang.RuntimeException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException : Result Maps collection already contains value for com.erp.webservice.inter.UsersMapper.BaseResultMap
     at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:113)
     at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:88)
     at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:325)
     at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:105)
     ... 4 more
Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.erp.webservice.inter.UsersMapper.BaseResultMap
     at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:710)
     at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:682)
     at org.apache.ibatis.session.Configuration.addResultMap(Configuration.java:473)
     at org.apache.ibatis.builder.MapperBuilderAssistant.addResultMap(MapperBuilderAssistant.java:204)
     at org.apache.ibatis.builder.ResultMapResolver.resolve(ResultMapResolver.java:44)
     at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:277)
     at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:244)
     at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java:236)
     at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:109)
     ... 7 more
Exception in thread "main" java.lang.NullPointerException
     at com.erp.webservice.test.Test.main( Test.java:29)

后来发现是我运行了多次自动生成代码的程序,导致了com/erp/webservice/mapper/UsersMapper.xml的内容多出来很多,原来自动生成代码的时候生成的XML代码不是覆盖原来的,而是附加的XML的尾部的。

第一次运行自动生成代码程序:

mapper1

第二次运行自动生成代码程序:

mapper2

看看,XML文件明显大了很多,只要删掉原来的XML然后重新运行自动生成代码的程序即可。

Java+MySQL报错Value ‘0000-00-00’ can not be represented as java.sql.Date的解决方法

今天在做mybatis的时候,运行主程序遇到如下报错:

Value '0000-00-00' can not be represented as java.sql.Date

解决的方法是在mybatis的连接数据库配置文件中将

<property name="url" value="jdbc:mysql://127.0.0.1:3306/tqmall?useUnicode=true&amp;characterEncoding=UTF-8" />

改成:

<property name="url" value="jdbc:mysql://127.0.0.1:3306/tqmall?useUnicode=true&amp;characterEncoding=UTF-8&amp;zeroDateTimeBehavior=convertToNull" />

即添加了:

zeroDateTimeBehavior=convertToNull

这样就就解决问题了。

MySQL报错:1030 Got error 28 from storage engine

今天在工作的时候,MySQL一直报出代码为1030的错误:

1030 Got error 28 from storage engine

后来去查阅了下资料发现1030错误“28 from storage engine”的意思是没有足够的磁盘空间,去查看下系统的磁盘情况:

-> /root >df -h
文件系统              容量  已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
                      141G  141G   0  100% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                1013M     0 1013M   0% /dev/shm
/dev/sdb2             459G  135G  301G  31% /data1

想办法把使用了100%的磁盘清理一下就可以了。

Nginx报could not build the server_names_hash的解决方法

今天在我的pcDuino上搭建了Nginx服务器,添加了第二个域名,结果nginx -t的时候报错了:

[emerg] 2468#0: could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32
nginx: configuration file /etc/nginx/nginx.conf test failed

后来看了nginx.conf,发现里面设置server_names_hash_bucket_size的语句:

server_names_hash_bucket_size 64;

被注释掉了,将前面的#去掉就行了。

最后查了下找到http://www.cnblogs.com/zhxlsuyu/archive/2012/06/11/2545289.html

保存服务器名字的hash表是由指令 server_names_hash_max_size 和 server_names_hash_bucket_size所控制的。参数hash bucket size总是等于hash表的大小,并且是一路处理器缓存大小的倍数。在减少了在内存中的存取次数后,使在处理器中加速查找hash表键值成为可能。如果 hash bucket size等于一路处理器缓存的大小,那么在查找键的时候,最坏的情况下在内存中查找的次数为2。第一次是确定存储单元的地址,第二次是在存储单元中查找键值。因此,如果Nginx给出需要增大 hash max size 或 hash bucket size的提示,那么首要的是增大前一个参数的大小.