2017-09-08 1 views
2

私のプロジェクトでは、春に休止状態4を使用しています。日付の場合、すべてのエンティティで以下のようにorg.joda.time.LocalDateTimeを使用しています。datetime2をJoda LocalDateTimeにマップする方法

DateTimeFormat(pattern = "dd-MMM-yyyy") 
@Column(name = "requiredDate", nullable = false) 
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime") 
private LocalDateTime requiredDate; 

エンティティを永続化している間、datetime2データ型として保持しています。エンティティ基準でエンティティをフェッチするときに問題は発生しません。しかし、私は選択フィールドのクエリを実行すると、私は日付フィールドのIllegalArgumentExceptionを取得しています。

ここにDAOの方法があります。ここで

public List<LeaseRequestDTO> listRequestsByRequester(String userId) { 
    List<LeaseRequestDTO> leaseRequestDTOS = getEntityManager() 
      .createQuery(
        "select " + 
          "  p.id as id, " + 
          "  p.requestNo as requestNo, " + 
          "  p.requestDate as requestDate, " + 
          "  p.status as status " + 
          "  from LeaseRequest p " + 
          "  where p.active LIKE true") 
      .unwrap(Query.class) 
      .setResultTransformer(Transformers.aliasToBean(LeaseRequestDTO.class)).list(); 
    return leaseRequestDTOS; 
} 

ここに私のDTOクラス

@Data 
public class LeaseRequestDTO { 
    private long id; 
    private String requestNo; 
    private LocalDateTime requestDate; 
    private String requesterId; 
    private LocalDateTime approvedDate; 
    private String processInstanceId; 
    private String status; 
    private String costCenterNo; 
} 

は、私が取得していますエラーです。

IllegalArgumentException occurred while calling setter for property [sg.com.ctc.eportal.core.dto.LeaseRequestDTO.requestDate (expected type = java.time.LocalDateTime)]; target = [LeaseRequestDTO(id=3, requestNo=GL1700001, requestDate=null, requesterId=null, approvedDate=null, processInstanceId=null, status=null, costCenterNo=null)], property value = [2017-09-08T12:40:52.281] setter of sg.com.ctc.eportal.core.dto.LeaseRequestDTO.requestDate 
IllegalArgumentException occurred while calling setter for property [sg.com.ctc.eportal.core.dto.LeaseRequestDTO.requestDate (expected type = java.time.LocalDateTime)]; target = [LeaseRequestDTO(id=3, requestNo=GL1700001, requestDate=null, requesterId=null, approvedDate=null, processInstanceId=null, status=null, costCenterNo=null)], property value = [2017-09-08T12:40:52.281] 
    at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:123) 
    at org.hibernate.transform.AliasToBeanResultTransformer.transformTuple(AliasToBeanResultTransformer.java:94) 
    at org.hibernate.hql.internal.HolderInstantiator.instantiate(HolderInstantiator.java:95) 
    at org.hibernate.loader.hql.QueryLoader.getResultList(QueryLoader.java:465) 
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370) 
    at org.hibernate.loader.Loader.list(Loader.java:2365) 
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:497) 
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387) 
    at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236) 
    at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1300) 
    at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103) 
    at sg.com.ctc.eportal.core.dao.impl.LeaseDAO.listRequestsByRequester(LeaseDAO.java:52) 
    at sg.com.ctc.eportal.core.service.impl.LeaseService.listRequestsByRequester(LeaseService.java:152) 
    at sg.com.ctc.eportal.core.service.impl.LeaseServiceTest.listRequestDTOByRequester(LeaseServiceTest.java:407) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) 
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) 
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) 
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193) 
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137) 
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) 
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) 
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237) 
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) 
Caused by: java.lang.IllegalArgumentException: argument type mismatch 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:68) 
    ... 46 more 

答えて

0

この問題は解決しました。実際それは小さなミスです。 DTOではjava.time.LocalDateTimeを使用しましたが、私のエンティティではorg.joda.time.LocalDateTimeを使用しました。

DTOクラスをorg.joda.time.LocalDateTimeに変更した後に問題が解決しました。

関連する問題