首页 > 代码库 > mysql方言不支持blob类型解决方案

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

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="http://www.mamicode.com/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>

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