2017-11-21 5 views
0

私は、SQL Server 2016、Spring Boot 1.5.8、Hibernate 5.2、およびSpring Data JPAをHikari 2.7で使用しています。サービスはデシベルと対話するよりも、私は、標準的な春の方法を使用していますvarbinaryからBLOBへの変換はサポートされていません

# HIKARI 
spring.datasource.type=com.zaxxer.hikari.HikariDataSource 
spring.datasource.hikari.idle-timeout=10000 
spring.datasource.hikari.connection-test-query=SELECT 1 
spring.datasource.hikari.maximum-pool-size=8 
spring.datasource.hikari.auto-commit=false 

# DATABASE 
spring.datasource.url=jdbc:sqlserver://100000001:1433;databaseName=Asdf 
spring.datasource.username=... 
spring.datasource.password=... 
spring.datasource.testOnBorrow=true 
spring.datasource.validationQuery=SELECT 1 
spring.datasource.continue-on-error=true 


# JPA 
spring.jpa.hibernate.ddl-auto=update 
spring.jpa.properties.hibernate.dialect=com......config.SqlServer2012CustomDialect 
spring.jpa.database=sql_server 
spring.jpa.show-sql=true 
spring.jpa.properties.hibernate.jdbc.batch_size=100 
spring.jpa.properties.hibernate.cache.use_second_level_cache=false 
spring.jpa.properties.hibernate.order_inserts=true 
spring.jpa.properties.hibernate.order_updates=true 
spring.jpa.hibernate.use-new-id-generator-mappings=true 

public class SqlServer2012CustomDialect extends SQLServer2012Dialect { 
    public SqlServer2012CustomDialect() { 
     registerColumnType(Types.VARBINARY, FINGERPRINT_COLUMN_LENGTH, FINGERPRINT_COLUMN); 
     registerColumnType(Types.VARBINARY, "VARBINARY(MAX)"); 
     //registerColumnType(Types.VARBINARY, "BLOB"); 
     //registerColumnType(Types.VARBINARY, "BINARY"); 
    } 
} 

public final class DatabaseColumnDefinitions { 
    private DatabaseColumnDefinitions(){} 

    public static final String FINGERPRINT_ENCODING = "UTF-8"; 
    public static final Charset FINGERPRINT_ENCODING_CHARSET = Charset.forName(FINGERPRINT_ENCODING); 

    public static final String FINGERPRINT_COLUMN = "VARBINARY(16)"; 
    public static final int FINGERPRINT_COLUMN_LENGTH = 16; 
} 

は、エンティティ、JpaRepositoriesを作りました。問題は、byte[]マッピングを自分のエンティティで動作させることができないことです。休止状態による任意の相互作用が例外をスロー:

com.microsoft.sqlserver.jdbc.SQLServerException: The conversion from varbinary to BLOB is unsupported. 

私が話していたエンティティ:VARBINARY(16) NOT NULL、データベース上で作成した列が正しい

@Entity 
@Table(
     uniqueConstraints = { 
       @UniqueConstraint(name = "rdjsonstore_fingerprint_unique",columnNames = "fingerprint") 
     } 
) 
public class RDJsonStore implements Serializable, FingerprintIndexer { 

    @Column(nullable = false) 
    @Id 
    @GeneratedValue(generator = "rdjsonstore_sequence", strategy = GenerationType.SEQUENCE) 
    @SequenceGenerator(name = "rdjsonstore_sequence", sequenceName = "rdjsonstore_sequence", allocationSize = 10000) 
    private Long id; 

    @Lob 
    @Basic 
    @Column(nullable = false, length = FINGERPRINT_COLUMN_LENGTH, columnDefinition = FINGERPRINT_COLUMN) 
    private byte[] fingerprint; 

    ... 

が、私はからリポジトリを呼び出すしようとすると、私はエラーが備わっ取得rdJsonStoreRepository.findAll(new PageRequest(0,10))のようなサービス:

ERROR 4980 --- [p-nio-80-exec-4] o.h.engine.jdbc.spi.SqlExceptionHelper : The conversion from varbinary to BLOB is unsupported. 
org.springframework.orm.jpa.JpaSystemException: could not execute query; nested exception is org.hibernate.exception.GenericJDBCException: could not execute query 
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:333) 
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:244) 
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:488) 
    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59) 
    at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213) 
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
    at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) 
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) 
    at com.sun.proxy.$Proxy128.findAll(Unknown Source) 

答えて

0

私はから@Lobを削除する必要がありました0フィールド。 @Lobは、varbinary(max)(および他のより大きな列タイプがサポートされている)で動作するはずです。

関連する問題