我正在使用HSQLDB进行测试。通过扫描模型从Spring创建数据库。其中一个模型是包含附件的消息(因此产生了一个高架)。尝试使用附件保存消息时,会导致: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;
}
答案 0 :(得分:2)
字节数组不会自动映射到Lob。您可能需要将@Lob
注释添加到属性中。
答案 1 :(得分:0)
我不知道这与你的问题有什么关系,但是:
为什么要Byte[]
代替byte[]
?这是一个巨大的开销,没有任何收获。我不知道任何处理Byte
对象数组的库。您应该将类型更改为byte[]
!