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 문제로 변경 한 후 해결되었습니다.