我有一个映射器方法,定义如下
@InsertProvider(type = ActivityMapperSQLBuilder.class, method = "insertIntoActivityComment")
public int insertIntoActivityComment(@Param("activityComment")ActivityComment activityComment);
对应的 SQLBuilder 方法定义为
public String insertIntoActivityComment(Map<String, Object> params) {
ActivityComment activityComment = (ActivityComment) params
.get("activityComment");
params.put("fileIds", activityComment.getFileIds());
params.put("commentType",activityComment.getCommentType());
params.put("commentText",activityComment.getCommentText());
params.put("commentingUserId",activityComment.getCommentingUser().getId());
params.put("attachments",activityComment.getAttachments());
params.put("activityId",activityComment.getActivity().getId());
StringBuilder builder = new StringBuilder(
"insert into activityComment (commenttype, commenttext, commentdate, commentinguser_id, attachments, activity_id, fileids) VALUES "
+ " (#{commentType}, #{commentText}, now(), #{commentingUserId}, #{attachments}, #{activityId}, #{fileIds} )");
return builder.toString();
}
每当我如下调用我的 mappermethod 时
getActivityMapper().insertIntoActivityComment(activityComment);
我遇到了以下错误。
error updating database. Cause: org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of java.util.ArrayList. Use setObject() with an explicit Types value to specify the type to use.
错误可能涉及ActivityMapper.insertIntoActivityComment-Inline 设置参数时出错\n### SQL: insert into activityComment (commenttype, commenttext, commentdate,commentinguser_id, attachments, activity_id, fileids) VALUES (?, ?, now(), ?, ?, ?, ? )\n### 原因:org.postgresql.util.PSQLException:无法推断用于 java.util.ArrayList 实例的 SQL 类型。使用带有显式类型值的 setObject() 来指定要使用的类型。”
我的 ActivityComment 对象的结构是
public class ActivityComment implements Serializable, IsSerializable {
private static final long serialVersionUID = 1L;
private int id;
private ActivityCommentType commentType;
private String commentText;
private Timestamp commentDate;
private Assignment activity;
private User commentingUser;
private String attachments;
private List<Integer> fileIds = new ArrayList<Integer>();
/*getters and setters*
}
谁能帮我将 ArrayList 插入 postgresql 数据库?