title: Hibernate 5 breaks legacy handling of Java UUID in Postgresql
body: <p>Upgrading one of our framework libraries caused our version of Hibernate to upgrade from 4 to 5. In doing so, now our queries to our PostgreSQL database are failing with the following exception.</p>
  
  <blockquote>
    <p>Caused by: org.postgresql.util.PSQLException: ERROR: operator does not
    exist: bytea = uuid   Hint: No operator matches the given name and
    argument type(s). You might need to add explicit type casts.<br>
    Position: 1827</p>
  </blockquote>
  
  <p>The problem seems to be converting from bytea to a Java UUID. All of our record id's are Java UUID's written to bytea to the database as was the norm in Hibernate 4. Below is the JPA annotations used to define the id field. We had no issues with this in Hibernate 4 and I suspect that I need to changes my annotations to get it to work again in Hibernate 5</p>
  
  <pre><code>@Id
  @GeneratedValue(generator = "uuid2")
  @GenericGenerator(name = "uuid2", strategy = "uuid2")
  private UUID id;
  </code></pre>
  
  <p>I noticed that a change added to org.hibernate.type.PostgresUUIDType was the addition of the method:</p>
  
  <pre><code>@Override
  protected boolean registerUnderJavaType() {
      // register this type under UUID when it is added to the basic type registry
      return true;
  }
  </code></pre>
  
  <p>which i presume defaults the handling of Java UUID's to the PostgreSQL's native UUID type. This change was make specifically in Hibernate 5 (<a href="https://hibernate.atlassian.net/browse/HHH-9577" rel="nofollow">https://hibernate.atlassian.net/browse/HHH-9577</a>)</p>
  
  <p>My question is how do i get back Hibernate 4 behavior back as we already have an existing database schema in place.</p>
  
  <p>Thank you.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I found the migration guide documented here: <a href="https://github.com/hibernate/hibernate-orm/blob/5.0/migration-guide.adoc" rel="nofollow">https://github.com/hibernate/hibernate-orm/blob/5.0/migration-guide.adoc</a></p>
  
  <p>it states the following:</p>
  
  <blockquote>
    <p>For ids defined as UUID with generation, for some databases it is
    required to explicitly set the @Column( length=16 ) in order to
    generate BINARY(16) so that comparisons properly work.</p>
  </blockquote>
  
  <p>I tried this and still no change in behavior.</p>