2017-05-18 13 views
1

spring-boot-startter-data-jpa-1.5.2.RELEASEを使用して、スプリングブートRESTサーバーを開発しています。私は次のPOJOクラス階層を持っています。まず、基本クラスのエンティティ:spring-data-rest:クエリパラメータが@DateTimeFormatと一致したときに「Unparseable date」を返すクエリ

@javax.persistence.Entity 
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) 
public abstract class Entity implements Serializable {  

    @Id 
    @Column(name = "id", nullable = false, length = 48) 
    public String id = UNINITIALIZED_ID; 

    /** 
    * The timestamp for when this entity was last updated. 
    */ 
    @Column(columnDefinition = "timestamp with time zone") 
    @Temporal(TemporalType.TIMESTAMP) 
    public Date updateTimestamp; 

} 

次具象サブクラスの患者:

@javax.persistence.Entity 
@Table(indexes={@Index(columnList="updateTimestamp")}) 
public class Patient extends Entity { 
... 
} 

そのupdateTimestamp指定されたタイムスタンプの後にある患者をフェッチするためにカスタムメソッドを次のように私は私のPatientRepositoryインターフェイスを定義します。私は、私はタイムスタンプを指定する形式は一貫ウィットであってもRESTクエリを行使するとき、私は日付のパースエラーを取得するいくつかの未知の理由のため

@RepositoryRestResource(collectionResourceRel = "patients", path = "patients") 
public interface PatientRepository extends JpaRepository<Patient, String> { 
    List<Patient> findByUpdateTimestampAfter(@DateTimeFormat(iso=DateTimeFormat.ISO.DATE_TIME)@Param("after")Date after); 
} 

// url example. DateFormat matches @DateTimeFormat on param in query method. 
GET http://127.0.0.1:8090/patients/search/findByUpdateTimestampAfter?after=2030-01-10T00:00:00.000-05:00 

私のサーバーでのスタックトレースは次のとおりです:

時間、彼は私がクエリのために使用します(ISO = DateTimeFormat.ISO.DATE_TIME)

URLがある@DateTimeFormatを経由して、クエリメソッドで指定された形式

Caused by: org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.format.annotation.DateTimeFormat @org.springframework.data.repository.query.Param java.util.Date] for value '2030-01-10T00:00:00.000-05:00'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2030-01-10T00:00:00.000-05:00] 
    at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:43) ~[spring-core-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:203) ~[spring-core-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.data.repository.support.ReflectionRepositoryInvoker.convert(ReflectionRepositoryInvoker.java:250) ~[spring-data-commons-1.13.1.RELEASE.jar:na] 
    ... 59 common frames omitted 
Caused by: java.lang.IllegalArgumentException: Parse attempt failed for value [2030-01-10T00:00:00.000-05:00] 
    at org.springframework.format.support.FormattingConversionService$ParserConverter.convert(FormattingConversionService.java:204) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.format.support.FormattingConversionService$AnnotationParserConverter.convert(FormattingConversionService.java:320) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:37) ~[spring-core-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    ... 61 common frames omitted 
Caused by: java.text.ParseException: Unparseable date: "2030-01-10T00:00:00.000-05:00" 
    at java.text.DateFormat.parse(DateFormat.java:366) ~[na:1.8.0_60] 
    at org.springframework.format.datetime.DateFormatter.parse(DateFormatter.java:157) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.format.datetime.DateFormatter.parse(DateFormatter.java:43) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    at org.springframework.format.support.FormattingConversionService$ParserConverter.convert(FormattingConversionService.java:198) ~[spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE] 
    ... 63 common frames omitted 

ここからどこへ行くべきですか?

答えて

1

私は愚かな愚かさを見ることができたコードを以下でテストプログラムを使用:

try { 
    Date now = new Date(); 
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); 
    String str = dateFormat.format(now); 
    Date date = dateFormat.parse(str); 
} catch (Exception ex) { 
    Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex); 
} 

問題は、私は05:00の代わり0500としてTimezoneを指定したURLの最後のビットでした。これは、org.springframework.format.annotation.DateTimeFormatのenum DATE_TIMEのJavadocの間違った例をコピー貼り付けに基づいていました。素晴らしい春のチームが聞いている場合は、Javadocを少し修正してください。ありがとうございました。

関連する問題