用entityManager.createNativeQuery(sql).list()查询blob数据时,抛出了下面的异常:
Caused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: -4
at org.hibernate.dialect.TypeNames.get(TypeNames.java:56)
at org.hibernate.dialect.TypeNames.get(TypeNames.java:81)
at org.hibernate.dialect.Dialect.getHibernateTypeName(Dialect.java:370)
其中entityManager为javax.persistence.EntityManager类型,此时,需要注册BLOB类型,编写一个继承MySQL5Dialect的类:
然后在persistence.xml配置文件里修改数据库方言声明:
<property name="hibernate.dialect" value="com.kin.mail.dialect.BlobMySQLDialect" />