SQL Server 2008、JDO (Datanucleus 3.0.7) 和列最大长度

发布于 2025-01-04 18:12:30 字数 2324 浏览 5 评论 0原文

我正在使用 SQL Server 2008,并且以下 jar 位于我的类路径中:

datanucleus-api-jdo-3.0.6.jar
datanucleus-core-3.0.8.jar 
datanucleus-enhancer-3.0.1.jar 
datanucleus-rdbms-3.0.7.jar

首先我想说的是一切正常。

我成功地保留了一个对象,该对象具有一个应该包含 ASCII 文件内容的字符串字段。

当文件较大时,我在坚持时会收到此错误:

javax.jdo.JDOFatalUserException:尝试存储值“|0|1.00|1.00|1.00||EUR” |8010312090196||ADVBANMMGM8|BA MASTER 米高梅 8|0|1.00|1.00|1.00||欧元 ”列“FILECONTENT”的最大长度为 256。请更正您的数据!

为了清楚起见,我修剪了引号之间的文件内容。

这是我的 package.jdo 文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jdo PUBLIC
    "-//Sun Microsystems, Inc.//DTD Java Data Objects Metadata 2.0//EN"
    "http://java.sun.com/dtd/jdo_2_0.dtd">
<jdo>
    <package name="com.mypackage.mycompany.model">

            <class name="FeedEvent" table="MY_UPLOADS" identity-type="application" >
                    <field name="id" persistence-modifier="persistent" primary-   key="true" value-strategy="identity" />
                    <field name="fileName" persistence-modifier="persistent" />
                    <field name="fileSize" persistence-modifier="persistent" />
                    <field name="fileContent" persistence-modifier="persistent"  />
                    <field name="uploaded" persistence-modifier="persistent" />
                    <field name="uploadDate" persistence-modifier="persistent" />
                    <field name="uploadFailureReason" persistence-modifier="persistent" />
                    <field name="eventDate" persistence-modifier="persistent" />
            </class>


    </package>
</jdo>

从 Windows 代码来看,一切正常,我们能够存储大至 1MB 的文件,所以我猜这与 DB 类型无关

public class FeedEvent {

private Long id;
private String fileName;
private long fileSize;
private String fileContent;
private boolean uploaded;
private Date uploadDate;
private String uploadFailureReason;
private Date eventDate;

public FeedEvent() {
}

.......getters and setters here..............

}

字段 fileContent 是在加载 ASCII 文件内容时出现问题的字段。 我尝试将列类型切换为 nvarchar(max)textvarchar(max) 但没有成功。

任何建议将不胜感激。

感谢您抽出时间。

I'm using SQL Server 2008 and the following jars are on my classpath:

datanucleus-api-jdo-3.0.6.jar
datanucleus-core-3.0.8.jar 
datanucleus-enhancer-3.0.1.jar 
datanucleus-rdbms-3.0.7.jar

I'd like to start with saying that everything works fine.

I persist successfully an object which has a String field that is supposed to contain an ASCII file content.

When the file is larger I get this error while persisting:

javax.jdo.JDOFatalUserException: Attempt to store value "|0|1.00|1.00|1.00||EUR
|8010312090196||ADVBANMMGM8|BA MASTER MGM 8|0|1.00|1.00|1.00||EUR
" in column "FILECONTENT" that has maximum length of 256. Please correct your data!

For the sake of clarity I trimmed down file content between quotation marks.

This is my package.jdo file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jdo PUBLIC
    "-//Sun Microsystems, Inc.//DTD Java Data Objects Metadata 2.0//EN"
    "http://java.sun.com/dtd/jdo_2_0.dtd">
<jdo>
    <package name="com.mypackage.mycompany.model">

            <class name="FeedEvent" table="MY_UPLOADS" identity-type="application" >
                    <field name="id" persistence-modifier="persistent" primary-   key="true" value-strategy="identity" />
                    <field name="fileName" persistence-modifier="persistent" />
                    <field name="fileSize" persistence-modifier="persistent" />
                    <field name="fileContent" persistence-modifier="persistent"  />
                    <field name="uploaded" persistence-modifier="persistent" />
                    <field name="uploadDate" persistence-modifier="persistent" />
                    <field name="uploadFailureReason" persistence-modifier="persistent" />
                    <field name="eventDate" persistence-modifier="persistent" />
            </class>


    </package>
</jdo>

From windows code everything works fine and we're able to store files as big as 1MB so I guess is not related to DB type.

This is my POJO:

public class FeedEvent {

private Long id;
private String fileName;
private long fileSize;
private String fileContent;
private boolean uploaded;
private Date uploadDate;
private String uploadFailureReason;
private Date eventDate;

public FeedEvent() {
}

.......getters and setters here..............

}

Field fileContent is the one that gives problems when loaded with an ASCII file content.
I tried to switch column type to nvarchar(max), text, varchar(max) but no luck.

Any suggestion would be greatly appreciated.

Thanks for your time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小糖芽 2025-01-11 18:12:30

我宁愿不把事情交给“运气”。 JDO 规范有明确定义的设置列长度的方法;参考任何 JDO 书籍或 DataNucleus 的文档都会告诉您有关 XML 元素 的足够清楚的信息,并且还会告诉您 persistence-modifier="persistent"绝大多数 java 字段类型不需要

I prefer to not leave things to "luck". The JDO spec has well defined ways of setting the length of a column; referring to any JDO book, or the documentation for DataNucleus would tell you clear enough about XML element <column> and would also tell you that persistence-modifier="persistent" is not needed for the vast majority of java field types

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文