论坛首页 Java企业应用论坛

奇怪的iBatis 乱码问题,insert正常update乱码且与日期有关

浏览 2641 次
该帖已经被评为隐藏帖
作者 正文
   发表时间:2008-05-14  
domain: ResourceType,Resource
dao:  ResourceTypeDao , ResourceDao

public class Resource   {
        private Long id;

private String name;

private String label;

private ResourceType resourceType;

private Date createdTime;

private Date modifiedTime;
.........................
}

问题:在写测试代码时,先创建了一个ResourceType保存到数据库中,再创建一个Resource保存到数据库,之后再更改Resource对象的属性update数据库中记录,但此时,Resource的name属性在数据库中就成了乱码,但其它的String类属性都 正常,且name属性的乱码与中英文无关。更奇怪的事,当不给第一次保存和之后更新时如果不给Resource的Date类的字段赋值,就一切正常,或不使用ResourceTypeDao创建并保存ResourceType对象而是直接先在数据库中写好的话,也不会出现乱码。
      错误(乱码)与产生这一错误的影响因素(Resource中的时间, 使用第一个ResourceTypeDao  )  。脑袋中目前是真想不出有什么联系,还请帮帮忙!


另外测试过如果ResourceDao如果不用iBatis而有JDBC实现,就不会有问题。
public static void main(String[] args) {

ApplicationContext context = new FileSystemXmlApplicationContext("D:/workspace/rhyton/src/spring-config/applicationContext*.xml");

ResourceTypeDao resourceTypeDao = (ResourceTypeDao) context.getBean("resourceTypeDao");

ResourceDao resourceDao = (ResourceDao) context.getBean("resourceDao");


ResourceType resType = new ResourceType();
resType = new ResourceType();
resType.setName("菜单");
resType.setResCode("1");
resourceTypeDao.save(resType);


Resource res = new Resource();
res.setLabel("label");
res.setName("name");
res.setResourceType(resType);
res.setModifiedTime(new Date());
res.setCreatedTime(new Date());
resourceDao.save(res);


Resource aResource = resourceDao.get(res.getId());
System.out.println(aResource);

res.setLabel("label-中文-9");
res.setName("name-中文-9");
res.setModifiedTime(new Date());
res.setCreatedTime(new Date());
resourceDao.save(res);

aResource = resourceDao.get(res.getId());
System.out.println(aResource);

}


日志如下:

log4j:WARN No appenders could be found for logger (com.rhyton.framework.component.orgAuth.dao.ResourceDaoTest).
log4j:WARN Please initialize the log4j system properly.
2008-05-14 11:04:42,766 DEBUG [java.sql.PreparedStatement] - {pstm-100001} Executing Statement: SELECT RH_COMMON_SEQ.nextval as id from dual
2008-05-14 11:04:42,766 DEBUG [java.sql.PreparedStatement] - {pstm-100001} Parameters: []
2008-05-14 11:04:42,766 DEBUG [java.sql.PreparedStatement] - {pstm-100001} Types: []
2008-05-14 11:04:42,938 DEBUG [java.sql.PreparedStatement] - {pstm-100003} Executing Statement:       INSERT INTO RH_RES_TYPES ( RES_TYPE_ID, TYPE_NAME, RES_CODE) VALUES (?,?,?) 
2008-05-14 11:04:42,938 DEBUG [java.sql.PreparedStatement] - {pstm-100003} Parameters: [622, 菜单, 1]
2008-05-14 11:04:42,938 DEBUG [java.sql.PreparedStatement] - {pstm-100003} Types: [java.lang.Long, java.lang.String, java.lang.String]
2008-05-14 11:04:42,969 DEBUG [java.sql.PreparedStatement] - {pstm-100005} Executing Statement: SELECT RH_COMMON_SEQ.nextval as id from dual
2008-05-14 11:04:42,969 DEBUG [java.sql.PreparedStatement] - {pstm-100005} Parameters: []
2008-05-14 11:04:42,969 DEBUG [java.sql.PreparedStatement] - {pstm-100005} Types: []
2008-05-14 11:04:42,984 DEBUG [java.sql.PreparedStatement] - {pstm-100007} Executing Statement:       INSERT INTO RH_RES ( RES_ID, RES_NAME, RES_LABEL, CTIME, MTIME, RES_TYPE_ID) VALUES (?,?,?,?,?,?) 
2008-05-14 11:04:42,984 DEBUG [java.sql.PreparedStatement] - {pstm-100007} Parameters: [623, name, label, 2008-05-14 11:04:42.969, 2008-05-14 11:04:42.969, 622]
2008-05-14 11:04:42,984 DEBUG [java.sql.PreparedStatement] - {pstm-100007} Types: [java.lang.Long, java.lang.String, java.lang.String, java.sql.Timestamp, java.sql.Timestamp, java.lang.Long]
2008-05-14 11:04:42,984 DEBUG [java.sql.PreparedStatement] - {pstm-100009} Executing Statement:    SELECT RES_ID, RES_NAME, RES_LABEL, CTIME, MTIME, RES_TYPE_ID FROM RH_RES t   where t.RES_ID = ? 
2008-05-14 11:04:42,984 DEBUG [java.sql.PreparedStatement] - {pstm-100009} Parameters: [623]
2008-05-14 11:04:42,984 DEBUG [java.sql.PreparedStatement] - {pstm-100009} Types: [java.lang.Long]
com.rhyton.framework.component.orgAuth.domain.Resource@9644f6[
  id=623
  name=name
]com.rhyton.framework.component.orgAuth.domain.Resource@9644f6[
  label=name
  resourceType=com.rhyton.framework.component.orgAuth.domain.ResourceType@964518[
  id=622
  name=<null>
]
  createdTime=Wed May 14 11:04:42 CST 2008
  modifiedTime=Wed May 14 11:04:42 CST 2008
]
2008-05-14 11:04:43,031 DEBUG [java.sql.PreparedStatement] - {pstm-100012} Executing Statement:    UPDATE RH_RES SET RES_NAME=?,RES_LABEL= ?,RES_TYPE_ID= ?,MTIME= ? where RES_ID= ? 
2008-05-14 11:04:43,031 DEBUG [java.sql.PreparedStatement] - {pstm-100012} Parameters: [name-中文-9, label-中文-9, 622, 2008-05-14 11:04:43.031, 623]
2008-05-14 11:04:43,031 DEBUG [java.sql.PreparedStatement] - {pstm-100012} Types: [java.lang.String, java.lang.String, java.lang.Long, java.sql.Timestamp, java.lang.Long]
2008-05-14 11:04:43,031 DEBUG [java.sql.PreparedStatement] - {pstm-100014} Executing Statement:    SELECT RES_ID, RES_NAME, RES_LABEL, CTIME, MTIME, RES_TYPE_ID FROM RH_RES t   where t.RES_ID = ? 
2008-05-14 11:04:43,031 DEBUG [java.sql.PreparedStatement] - {pstm-100014} Parameters: [623]
2008-05-14 11:04:43,031 DEBUG [java.sql.PreparedStatement] - {pstm-100014} Types: [java.lang.Long]
com.rhyton.framework.component.orgAuth.domain.Resource@969aac[
  id=623
  name=�纄-中文-9
]com.rhyton.framework.component.orgAuth.domain.Resource@969aac[
  label=�纄-中文-9
  resourceType=com.rhyton.framework.component.orgAuth.domain.ResourceType@969ac1[
  id=622
  name=<null>
]
  createdTime=Wed May 14 11:04:42 CST 2008
  modifiedTime=Wed May 14 11:04:43 CST 2008
]
2008-05-14 11:04:43,062 DEBUG [java.sql.PreparedStatement] - {pstm-100017} Executing Statement: delete from RH_RES_TYPES where RES_TYPE_ID= ?
2008-05-14 11:04:43,062 DEBUG [java.sql.PreparedStatement] - {pstm-100017} Parameters: [622]
2008-05-14 11:04:43,062 DEBUG [java.sql.PreparedStatement] - {pstm-100017} Types: [java.lang.Long]
2008-05-14 11:04:43,125 DEBUG [java.sql.PreparedStatement] - {pstm-100019} Executing Statement: delete from RH_RES_TYPES where RES_TYPE_ID= ?
2008-05-14 11:04:43,125 DEBUG [java.sql.PreparedStatement] - {pstm-100019} Parameters: [null]
2008-05-14 11:04:43,125 DEBUG [java.sql.PreparedStatement] - {pstm-100019} Types: [null]
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics