title: Hibernate: Cannot find by UUID
body: <p>Im trying to use UUID's as ids for my database but I simply do not get it working.</p>
  <p>First attempt was:</p>
  <pre><code>@Id
  @GeneratedValue(generator = &quot;hibernate-uuid&quot;)
  @GenericGenerator(name = &quot;uuid&quot;, strategy = &quot;uuid4&quot;)
  private UUID id;
  </code></pre>
  <p>but this is generating some ugly byte code. So I added a type annotation:</p>
  <pre><code>@Id
  @GeneratedValue(generator = &quot;hibernate-uuid&quot;)
  @GenericGenerator(name = &quot;uuid&quot;, strategy = &quot;uuid4&quot;)
  @Type(type=&quot;org.hibernate.type.UUIDCharType&quot;)
  private UUID id;
  </code></pre>
  <p>with this I get a character representation in my mysql database but querying the database using my repository:</p>
  <pre><code>public interface CommentsRepository extends CrudRepository&lt;Comment, UUID&gt; {
  
      Comment findById(final UUID imageId);
  }
  </code></pre>
  <p>wont find any result - even if an entry with the given UUID exists it wont return the result.
  Even if I use plain SQL directly on my database it wont find any result.</p>
  <p>Is there something else I need to do to get UUID's working?</p>
  <p><strong>EDIT</strong></p>
  <p>Trying this:</p>
  <pre><code>@Data
  @Entity
  public class Comment implements Serializable {
  
      @Id
      @GeneratedValue(generator = &quot;uuid2&quot;)
      @GenericGenerator(name = &quot;uuid2&quot;, strategy = &quot;uuid2&quot;)
      @Type(type = &quot;uuid-char&quot;)
      private UUID id;
  }
  </code></pre>
  <p>and adding some default values:</p>
  <pre><code>@Component
  @Slf4j
  public class CommentsSampleData implements CommandLineRunner {
  
      private final CommentsRepository repository;
  
      @Autowired
      public CommentsSampleData(final CommentsRepository repository) {
          this.repository = repository;
      }
  
      @Override
      public void run(String... args) {
          repository.save(new Comment());
          repository.save(new Comment());
          repository.save(new Comment());
          repository.save(new Comment());
      }
  }
  </code></pre>
  <p>Results in the following table:</p>
  <p><a href="https://i.stack.imgur.com/yoroL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yoroL.png" alt="enter image description here" /></a></p>
  <p>performing:</p>
  <pre><code>SELECT * FROM comment WHERE id = 'b076a9f7-7e9e-4f5a-91f8-e66c7d076fac' 
  </code></pre>
  <p>results in:</p>
  <p><a href="https://i.stack.imgur.com/dX6El.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dX6El.png" alt="enter image description here" /></a></p>
  <p>which means no result but there should be one. Using jpa also does not return anything.</p>