mysql方言不支持blob类型解决方案

时间:2023-03-08 17:05:09

package com.gstone.history.entity;

import java.sql.Types;

import org.hibernate.Hibernate; import org.hibernate.dialect.MySQLDialect;

public class BlobMySQLDialect extends MySQLDialect{  public BlobMySQLDialect(){   super();    registerHibernateType(Types.LONGVARBINARY, Hibernate.BLOB.getName());  } }

然后在配置文件中,改方言:

<prop key="hibernate.dialect">
     com.gstone.history.entity.BlobMySQLDialect
 </prop>

<bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
  <property name="dataSource" ref="dataSource"></property>
  <property name="packagesToScan" value="com.gstone"/>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.show_sql">false</prop>
    <prop key="hibernate.dialect">
     com.gstone.history.entity.BlobMySQLDialect
    </prop>
    <prop key="hibernate.cache.provider_class">
     org.hibernate.cache.EhCacheProvider
    </prop>
    <prop key="hibernate.cache.provider_configuration_file_resource_path">
     spring/ehcache.xml
    </prop>
   </props>
  </property>
 </bean>