0

I'm using Micronaut Data JDBC 1.1.3 with a MySQL 8.0 database. I'd like to have my id columns use a BINARY(16) storage and use BIN_TO_UUID()/UUID_TO_BIN() to convert the values. I though I could do this with Micronaut Data's @ColumnTransformer, like this:

public class User {
    @Id
    @ColumnTransformer(read = "BIN_TO_UUID(user_.id)", write = "UUID_TO_BIN(?)")
    private UUID id;

    // ...
}

I then use a UserRepository like this:

@JdbcRepository(dialect = Dialect.MYSQL)
public interface UserRepository extends RxJavaCrudRepository<User, UUID> {
}

It works great in that the id column is correctly tranformed in query results. But when I try to find something by ID, using userRepository.findById(id).toSingle(), I get an error ("the MaybeSource is empty"), and I can see in the trace output the it is not tranforming the value:

15:17:04.878 [pool-1-thread-76] DEBUG io.micronaut.data.query - Executing Query: SELECT BIN_TO_UUID(user_.id) AS id,user_.`username` FROM `user` user_ WHERE (user_.`id` = ?)

Is this expected? Is there anything else I can do transform the query? Do I have to write an explicit query?

skagedal
  • 2,323
  • 23
  • 34

1 Answers1

1

I believe this is a bug in Micronaut-Data 1.1.3.

As a workaround I would override the query like:

@ReadOnly
@Override
@Query(
   "SELECT * FROM user WHERE user.id = :id")
Optional<User> findById(UUID id);

in the UserRepository interface.

BTW Query needs of cause to be customized for your needs.

  • Thank you Marc! I haven't yet gotten around to testing this, but will mark it as accepted as it looks right. :) Do you have any idea of there being a bug ticket somwhere I could follow? – skagedal Oct 11 '20 at 08:22
  • 1
    @skagedal It's already fixed in micronaut data 2.0 here is the link to the [fix](https://github.com/micronaut-projects/micronaut-data/commit/ab19a1acabcad9eb6a82cb533c8e61882947d972) which references to the bugticket. I've already upgraded and it works like a charm with uuid's. – Marc Nützel Oct 12 '20 at 09:17