【问题标题】:Blob size limit when using HSQLDB from spring从 spring 使用 HSQLDB 时的 Blob 大小限制
【发布时间】:2012-07-06 17:21:17
【问题描述】:

我正在使用 HSQLDB 进行测试。数据库是通过扫描模型从 spring 创建的。其中一个模型是包含附件的消息(因此导致 lob)。尝试保存带有附件的消息时,会导致:org.hsqldb.HsqlException:数据异常:字符串数据,右截断。附件最大只有 4kb。有没有办法从 spring 配置 hsql lob 字段的大小限制?我确定异常是由附件引起的,因为当我评论该行(添加附件)时一切正常。

我的弹簧配置:

<bean id="transactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager"
      autowire="autodetect">

    <property name="dataSource">
        <ref local="hsqlDbDataSource"/>
    </property>
</bean>

<bean id="persistenceManager"
      class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>

<bean class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">
    <property name="ignoreResourceNotFound">
        <value>true</value>
    </property>
    <property name="location">
        <!--  You may use file:d:/temp/db.properties etc here -->
        <value>classpath:dispatcher.model.db.properties</value>
    </property>
</bean>

<!-- HSQLDB DS -->
<bean id="hsqlDbDataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
    <property name="url" value="jdbc:hsqldb:mem:dispatcher"/>
    <property name="username" value="sa"/>
    <property name="password" value=""/>
    <property name="initialSize" value="20"/>
    <property name="maxActive" value="10"/>
    <property name="poolPreparedStatements" value="true"/>
    <property name="maxOpenPreparedStatements" value="10"/>
</bean>

<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="hsqlDbDataSource"/>

    <property name="packagesToScan">
        <list>
            <value>com.company.project.dispatcher.model.**.*</value>
        </list>
    </property>

    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
            <prop key="hibernate.generate_statistics">true</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.cache.use_second_level_cache">true</prop>
            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop>
            <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
       </props>
    </property>
</bean>

消息模型:

  public class FaxMessage extends Message implements  IFaxMessage {

/** Serial Version UID. */
private static final long serialVersionUID = -558902226L;   

/** Field mapping. */
private Long gatewayMessageId;
/** Field mapping. */
private Integer numberOfPages;
/** Field mapping. */
private Boolean pdfAttached;
/** Field mapping. */
private Byte[] pdfData;
/** Field mapping. */
private String subject;
/** Field mapping. */
private String tiffFileLocation;

...

/**
 * Return the value associated with the column: pdfData.
 * @return A Byte[] object (this.pdfData)
 */
@Basic( optional = true )
@Column( name = "pdf_data"  )
public Byte[] getPdfData() {
    return this.pdfData;

}

/**  
 * Set the value related to the column: pdfData.
 * @param pdfData the pdfData value you wish to set
 */
public void setPdfData(final Byte[] pdfData) {
    this.pdfData = pdfData;
}

【问题讨论】:

  • 你能发布有问题的模型定义吗?
  • 您确定它肯定使用的是 BLOB 吗?你能看到它生成的 DDL 吗?尝试将 @Lob 注释添加到属性以使其显式。

标签: java spring blob hsqldb lob


【解决方案1】:

字节数组不会自动映射到 Lob。您可能需要在属性中添加@Lob 注释。

【讨论】:

  • 添加@Lob 后一切正常!现在我必须弄清楚如何告诉自动生成器添加@Lob。谢谢!
【解决方案2】:

我不知道这是否与您的问题有关,但是:

为什么要Byte[] 而不是byte[]?有一个巨大的开销,没有任何收获。我不知道任何处理Byte 对象数组的库。您应该将类​​型更改为byte[]

【讨论】:

  • 模型是从 mysql 数据库自动生成的。我无法控制它使用什么类型。也就是说,我在必要时将Byte[] 更改为byte[] 无济于事。
  • @DanielCarabott 这么认为,但值得一试
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-17
  • 1970-01-01
  • 2020-09-23
  • 2011-12-25
  • 1970-01-01
  • 1970-01-01
  • 2015-12-23
相关资源
最近更新 更多