Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use spring data jpa with Micronaut?

I would like to extend my TestRepository interface with JpaRepository and utilize the features such as jpa method queries, paging and sorting without manually defining entity manager bean and without writing any sql. P.S. In micronaut project

like image 234
Khwaja Sanjari Avatar asked Nov 19 '18 19:11

Khwaja Sanjari


2 Answers

Edit - July 2019

They have announced a spring data equivalent named Micronaut Data


Micronaut does not support Spring's AOP implementation right now. So you should not expect to use an object as Repository by simply implementing JpaRepository<T,ID>

However you can write a spring based app/library then add this jar as a micronaut project dependency... It should work in theory. Maybe some kind of bridge needed to share environment/profile info and retrieve this repositories to micronaut context

Or, as mentinoned in comments, you can write your own Repository stubs with Introduction Advice of micronaut. If you generally use @Query annotation in spring repositories, it should be quite easy to implement an equivalent for micronaut app

like image 152
hgoz Avatar answered Nov 13 '22 01:11

hgoz


The Predator proyect was renamed Micronaut Data. There are already maven packages for milestone 1.

The documentation is quite good. You can use the same JPA annotated model with MicronautData repositories. You can use it with or without Hibernate. It is as easy as:

@Repository 
interface BookRepository extends CrudRepository<Book, Long> { 
    Book find(String title);
}

On the other hand. It seems that Spring repositories can be used with micronaut. Look at this official example

like image 2
borjab Avatar answered Nov 13 '22 01:11

borjab