Question

I'm using HSQLDB for testing. The database is created from spring by scanning the models. One of the models is a message which contains an attachment (Thus resulting in a lob). When trying to save a message with an attachment it results in a : org.hsqldb.HsqlException: data exception: string data, right truncation. The attachment is only 4kb max. Is there a way to configure size limit of hsql lob fields from spring ? I'm sure the exception is caused by the attachment because when I commented that line (add attachment) all worked fine .

My spring configuration :

<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>

Message Model :

  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;
}
Was it helpful?

Solution

A byte array is not automatically mapped to a Lob. You may need to add the @Lob annotation to the property.

OTHER TIPS

I don't know if that has anything to do with your problem, but:

Why would you want a Byte[] instead of a byte[]? There's a huge overhead and nothing gained. I am not aware of any library that processes Byte Object arrays. You should change the type to byte[]!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top