问题要点:
**
问题1描述:
** 我有一个mybatis查询,看起来像这样。
<select id="xyz" parameterType="com.test.VO" resultMap="abc" fetchSize="100" resultSetType="FORWARD_ONLY">
select tag.TAG_desc TAGNAME,
(det.tag_val_1 || det.tag_val_2 || det.tag_val_3 || det.tag_val_4 ||
det.tag_val_5 || det.tag_val_6 || det.tag_val_7 || det.tag_val_8 ||
det.tag_val_9 || det.tag_val_10) TAGVALUE,
det.tag_no||lpad(det.sub_fld, 2, '0') TAGID
from A det, B tag
where det.brch_code = #{branchCode}
and det.prod_ref_id = #{refId}
and det.tnx_id= #{tnxId}
and det.msg_type= #{messageNumber}
and det.msg_type = tag.msg_type
and (det.tag_no = tag.tag_no or substr(det.tag_no, 0, 2) = tag.tag_no )
and (det.tag_no = rpad(tag.tag_no, 3, '_') )
and det.tag_val_1 is not null
</select>
<resultMap id="abc" type="com.test.InstructionType$AdditionalInfo">
<result property="name" column="TAGNAME" />
<result property="id" column="TAGID" />
<result property="content" column="TAGVALUE" />
</resultMap>
它给我以下错误:
; uncategorized SQLException for SQL []; SQL state [72000]; error code [1489]; ORA-01489: result of string concatenation is too long
; nested exception is java.sql.SQLException: ORA-01489: result of string concatenation is too long
tag_val_1到tag_val_10最多可以有2K字符,这导致了上述问题。
问题2描述:
尝试将tag_val添加到ValueObject(VO)并在java中连接。
看起来像
<select id="XYZ" parameterType="com.test.OutboundInterfaceVO" resultMap="abc" fetchSize="100" resultSetType="FORWARD_ONLY">
select tag.TAG_desc TAGNAME,
(det.tag_val_1||det.tag_val_2)TAGVAL12,
(det.tag_val_3||det.tag_val_4 )TAGVAL34,
(det.tag_val_5||det.tag_val_6 )TAGVAL56,
(det.tag_val_7||det.tag_val_8||det.tag_val_9 || det.tag_val_10) TAGVALUE710,
from A det, B tag
where det.brch_code = #{branchCode}
and det.prod_ref_id = #{refId}
and det.tnx_id= #{tnxId}
and det.msg_type= #{messageNumber}
and det.msg_type = tag.msg_type
and (det.tag_no = tag.tag_no or substr(det.tag_no, 0, 2) = tag.tag_no )
and (det.tag_no = rpad(tag.tag_no, 3, '_') )
and det.tag_val_1 is not null
</select>
<resultMap id="abc" type="com.test.OutboundInterfaceVO">
<result property="tagName" column="TAGNAME" />
<result property="tagId" column="TAGID" />
<result property="tagVal12" column="TAGVAL12" />
<result property="tagVal34" column="TAGVAL34" />
<result property="tagVal56" column="TAGVAL56" />
<result property="tagVal710" column="TAGVAL710" />
</resultMap>
case1&gt;试图认为它正在返回一行(我的坏)
private String tagName;
private String tagId;
private String tagVal12;
private String tagVal34;
private String tagVal56;
private String tagVal710;
Case2&gt;因为查询成功返回,没有ORA错误(在PL / SQL Dev中检查)
问题在于resultmap,这次。
返回了大约30行,试图将它们作为字符串列表捕获,
private List<String[]> tagName = new ArrayList<String[]>();
private List<String[]> tagId = new ArrayList<String[]>();
private List<String[]> tagVal12 = new ArrayList<String[]>();
private List<String[]> tagVal34 = new ArrayList<String[]>();
private List<String[]> tagVal56 = new ArrayList<String[]>();
private List<String[]> tagVal710 = new ArrayList<String[]>();
使用java。
中的循环List<InstructionType> instructionList = mapper.pqr(interfaceVO);
for (InstructionType instructionType : instructionList) {
------
mapper.XYZ(VO);
for (InstructionType.AdditionalInfo addlist : instructionType.getAdditionalInfo())
{
addlist.setID(interfaceVO.getTagId());
addlist.setName(interfaceVO.getTagName());
content.append(interfaceVO.getTagVal12());
content.append(interfaceVO.getTagVal34());
content.append(interfaceVO.getTagVal56());
content.append(interfaceVO.getTagVal710());
addlist.setContent(content.toString());
}
}
instructionDetails.getInstruction().addAll(instructionList);
我的InstructionType类,有点帮助
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "InstructionType", namespace = "http://www.db.com/tf", propOrder = {
"additionalInfo"
})
public class InstructionType {
@XmlElement(name = "AdditionalInfo", namespace = "http://www.abc.com/tf")
protected List<InstructionType.AdditionalInfo> additionalInfo;
...along with setters and getters
public static class AdditionalInfo {
@XmlValue
protected String content;
@XmlAttribute(name = "Name", required = true)
protected String name;
@XmlAttribute(name = "ID")
protected String id;
.....along with setters and getter in each class
}
}
注意:我有mybatis 3.2.2和Oracle 11g,java 6
坚持那些家伙,解决问题1的任何帮助都可以避免问题2。 另外,请以更好的方式帮助我设置列表清单。
非常感谢你。
答案 0 :(得分:1)
您从Oracle DB收到错误。这与mybatis无关。错误信息非常清楚 如果我是你,我只是在Java中而不是在SQL中进行字符串连接。
答案 1 :(得分:0)
终于....发现提供给问题1的解决方案是返回30行而不是1行... 但是我把它设置成一个String变量...... !!(我的坏)
感谢大家的支持.. !!