我正在使用 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;
}