내가 사용하여 웹 서비스를 개발하고 있어요 eclipseLink 2.4.1
, JPA 2.0.1
및 기타 지원 도구를 제공합니다. 날짜 유형의 열이있는 테이블을 만들었습니다. 특정 날짜에 대한 기록을 얻고 싶습니다. mysql의 date_format을 사용하고 있으며 다음과 같은 오류가 발생합니다.
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing[select o from Clients o where FUNCTION('date_format',{o.effectiveStartDate},{d,'dd-mm-yyyy'})='27-05-2014']
[90, 111] The JDBC escape format does not start with either 'd', 't' or 'ts'.
[110, 110] The JDBC escape format is missing the close quote.
date_format을 다음과 같이 직접 호출하려고 시도했습니다.
Select o from Clients o where date_format(o.effectiveStartDate '%d-%m-%Y'})='27-05-2014'
그런 다음 구문 오류 구문 분석이 발생합니다. invalid token [(]
.
namedQuery도 시도했지만 성공하지 못했습니다.
이러한 함수 JPQL을 호출하는 방법.
"{o.effectiveStartDate}"는 무엇을하려고합니까? 중괄호를 제거하지 않으면 JDBC 이스케이프 구문 날짜로 해석하려고 시도합니다 (아님).
JPA 2.1 'FUNCTION'구문은 다음과 같습니다.
FUNCTION("date_format", o.effectiveStartDate, "the_date_format")
여기서 "the_date_format"은 http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format 에 따라 MySQL이 두 번째 인수에 대해 허용하는 것과 일치합니다.
물론 JPA2.1 호환 구현을 사용해야합니다. 구현에 다른 공급 업체별 FUNC가 있거나 그렇지 않은 경우 이식 가능하지 않을 수 있으며 필요한 작업을 수행해야하는 표준 변형이있을 시간이 없습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다