2017-05-02 7 views
0

私たちは、MSSQL DB上にLocalTimeと協力して、クエリでの問題にLocalTime

を持っている私たちのエンティティは、フィールド

@Column(name = "receipt_time", nullable = false) 
private LocalTime receiptTime; 

すべてがすなわちspring-を使用してクエリを実行する場合を除いて正常に動作していデータ-JPAクエリ

boolean existsByReceiptTime(LocalTime time); 

戻りThe data types time and datetime are incompatible in the equal to operator.

sendTimeAsDateTimeで解決しようとしましたが、動作しませんでした。 URL文字列は受け入れられませんでした。その後、私はいくつかのAttributeConvertersを無駄にしようとしました。その他の可能なアドバイスはありますか?注:私は本当にLocalTime型で滞在したいと思います。

UPDATE:生成 クエリは解決策は、カスタムコンバータ属性記述することです

Hibernate: select TOP(?) receipt0_.id as col_0_0_ from receipt receipt0_ where receipt0_.receipt_time=?' is the query. 
+0

我々はまた、正しい方言を使用しているSQLServer2012Dialect – Zveratko

+0

http://stackoverflow.com/questions/29517508/how-to-persist-jsr-310-types-with-spring-data-jpa –

+0

私は実際に私が書きましたそれは助けにはならなかった。上記のリンク – Zveratko

答えて

1

です。おそらく、Microsoft SQLサーバー固有のソリューションです。

@Converter(autoApply = true) 
public class LocalTimeConverter implements AttributeConverter<LocalTime, String> { 

    @Override 
    public String convertToDatabaseColumn(LocalTime time) { 
     return time.toString(); 
    } 

    @Override 
    public LocalTime convertToEntityAttribute(String time) { 
     return LocalTime.parse(time); 
    } 
} 
関連する問題