Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is a Hibernate JPQL Type Cast necessary for String
    primarykey
    data
    text
    <p>I am using the Play! Framework for a small application. In a Model I have the following Query:</p> <pre><code>public static ApplicationUser getByUserName(String userName) { return ApplicationUser.find("SELECT u FROM ApplicationUser u WHERE u.userName = ?", userName).first(); } </code></pre> <p>This works perfectly with the in memory DB H2 but when I use Postgres I get the following error:</p> <pre><code>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 </code></pre> <p>When I cast the parameter like:</p> <pre><code>ApplicationUser.find("SELECT u FROM ApplicationUser u WHERE u.userName = CAST(? AS string)", userName).first() </code></pre> <p>Then it works. But why is this necessary. Could that be a Hibernate bug?</p> <p><strong>Update:</strong> I downgraded the play Version from 1.2.4 to 1.2.3 and now it works. I think the problem lies in the shipped postgres jdbc driver probably.</p> <p><strong>Update II</strong>: The problem is still not solved. I get the same error again for the query:</p> <pre><code>ApplicationRole.find("byName", name).first(); </code></pre> <p>The error:</p> <pre><code>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. </code></pre> <p>In <code>application.conf</code> I have:</p> <blockquote> <p>jpa.dialect=org.hibernate.dialect.PostgreSQLDialect</p> </blockquote> <p>Nobody having this error?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload