开发者

Why JPA, Hibernate and jTDS always uses varchar(8000) for String columns?

I'm using JPA (Hibernate) and jTDS as my jdbc driver. Whenever the datatype of my entity columns are String, the created prepared statement uses varchar(8000) as its parameter. I've already tried to use @Column(length=50) in my mappings for example, but it seems to be ignored.

If I set sendStringParametersAsUnicode in jTDS connection, i开发者_JAVA百科t uses nvarchar(4000) instead, but never respects the lentghs I define in my entities. Is there a reason for that?


I realize this is an old question, but having recently run into this myself I thought I'd shed some light.

This seems to be intentional in the jtds driver.

If you look at TdsData.java, you will see this occur in this code-block:

} else {
    if (pi.isUnicode && len <= MS_LONGVAR_MAX / 2) {
        pi.tdsType = XSYBNVARCHAR;
        pi.sqlType = "nvarchar(4000)";
    } else if (!pi.isUnicode && len <= MS_LONGVAR_MAX) {
        CharsetInfo csi = connection.getCharsetInfo();
        try {
            if (len > 0 && csi.isWideChars() &&
            pi.getBytes(csi.getCharset()).length > MS_LONGVAR_MAX) {
                pi.tdsType = SYBTEXT;
                pi.sqlType = "text";
            } else {
                pi.tdsType = XSYBVARCHAR;
                pi.sqlType = "varchar(8000)";
            }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜