1

I'm using Micronaut Data JDBC (not JPA). It works fine with queries, where I can extend the CrudRepositry interface and add the queries as needed. For example:

@JdbcRepository
public interface MyRespository extends CrudRepository<MyEntity, String> {

   @Query(
      value = "...",
      countQuery = "..."
   )
   Page<String> findByNameEquals(String name, Pageable pageable);
}

All seems fine until I want to override the save(MyEntity myEntity) method. I'm expecting something like this:

    @Insert(
       value = "insert into my_entity (id, name) values (uuid_to_bin(uuid()), :myEntity.name" 
    )
    public MyEntity(MyEntity myEntity)

But it doesn't seem to exist.

Does it mean I have to write another class for this save method, and as a result will end up with two repository classes, one for queries and one for overriding the save method? If yes how do I get a database connection object with which I can create and execute my sql statement?

Thanks! -Fujian

Roshin Raphel
  • 2,612
  • 4
  • 22
  • 40
Fujian Y.
  • 11
  • 1
  • ended up implementing a new repository class that has DataSource injected. Would be nice to have the @Insert annotation though. – Fujian Y. Sep 24 '20 at 15:39

0 Answers0