2011-12-09 5 views
4
나는 플레이를 사용하고

필요 캐스트 왜! 작은 응용 프로그램을위한 프레임 워크. 모델에서 나는 다음과 같은 쿼리가 :하이버 네이트 JPQL 유형이 문자열

public static ApplicationUser getByUserName(String userName) { 
    return ApplicationUser.find("SELECT u FROM ApplicationUser u WHERE u.userName = ?", userName).first(); 
} 

이 메모리 DB H2에서 완벽하게 작동하지만 내가 포스트 그레스를 사용할 때 다음과 같은 오류를 얻을 : 내가 좋아하는 매개 변수를 캐스팅

22:57:10,371 WARN ~ SQL Error: 0, SQLState: 42883 
22:57:10,371 ERROR ~ ERROR: operator does not exist: character varying = bytea 
    Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts. 
    Position: 167 

:

ApplicationUser.find("SELECT u FROM ApplicationUser u WHERE u.userName = CAST(? AS string)", userName).first() 

그러면 작동합니다. 그러나 이것이 필요한 이유는 무엇입니까? 그것은 최대 절전 모드 버그 일 수 있습니까?

업데이트 : 재생 버전을 1.2.4에서 1.2.3으로 다운 그레이드하여 이제는 작동합니다. 나는 문제가 아마도 제공 포스트 그레스 JDBC 드라이버에있다 생각합니다.

업데이트 II : 문제는 여전히 해결되지 않습니다. 나는 쿼리에 대해 다시 같은 오류가 발생합니다 :

ApplicationRole.find("byName", name).first(); 

오류 : application.conf에서

JPAQueryException occured : Error while executing query SELECT u FROM ApplicationUser u WHERE u.userName = ?: ERROR: operator does not exist: character varying = bytea Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts. 

내가 가진 :

jpa.dialect=org.hibernate.dialect.PostgreSQLDialect

아무도이 오류가없는?

답변

2

를 교체하려고? (? 1) 에 의해 같이 :

public static ApplicationUser getByUserName(String userName) { 
    return ApplicationUser.find("SELECT u FROM ApplicationUser u WHERE u.userName = (?1)", userName).first(); 
} 

나는 비슷한 쿼리를 가지고 잘 작동합니다. 나는-발견 자동 또는 PosgreSQL에 도미니크 제안으로, 당신의 jpa.dialect로 설정되어 있는지 확인 (단지의 경우!) 또한

ApplicationUser에서는 String 형이다 분야 이름을 믿고있어.

+0

. 1.2.4에서 1.2.3으로 플레이를 다운 그레이드했습니다. 이제 모든 것이 정상적으로 작동합니다. – reen

+0

그것은 지금 나를 도왔다. 감사. 늦은 답변 죄송합니다 – reen

4

conf/application.conf에서 postgresql 데이터베이스 언어를 활성화 했습니까?

jpa.dialect = org.hibernate.dialect.PostgreSQLDialect

+0

. 1.2.4에서 1.2.3으로 플레이를 다운 그레이드했습니다. 이제 모든 것이 정상적으로 작동합니다. 내 업데이트를 참조하십시오 – reen

1

나는 1.2.4, 동일한 문제가 있습니다.

User.find("byEmail", email).first() 

당신으로 그 똑같은 캐스팅 오류를 얻을, 그래서 ...
User.find("byEmailAndPassword", email, password).first() 

가 여전히 작동,

User.find("email = (?1)", email).first() 

흥미롭게도 (감사 페레)로 교체했다

내 업데이트를 참조하십시오
관련 문제