0

I am using Hexagonal Architecture, Hibernate Reactive with Panache and Quarkus in a Kotlin Project.

Transaction boundaries are set using @ReactiveTransactional annotation.

The problem is that I had to add the whole Hibernate Reactive with Panache dependency in the domain and application layers just to make this annotation available.

Is there a way to avoid this?

I was hoping it would be possible to create a domain annotation and then in the adapters layer replace it with the @ReactiveTransactional somehow.

AmsterdamLuis
  • 341
  • 3
  • 21

2 Answers2

0

You could remove the annotation from the class, and wrap it into a service, and implement this service in the adapter layer using the annotation.

choquero70
  • 4,470
  • 2
  • 28
  • 48
  • That would force me to write a lot of boilerplate code, since I would have to add an extra field in every class and wrap every call. Using an annotation is so much more convenient. I guess I'll have to either make a PR to Panache or write some custom annotation processor. – AmsterdamLuis Mar 24 '22 at 08:46
  • That's the price you have to pay if you want to be purist decoupling code. For some issues maybe it's better to break the rule. For example I use lombok at the domain. In your case, Vaughn Vernon in the red book examples uses @Transactional at the domain too. I think that I would use the framework annotation as well because writing a custom one is finally the same, not worth it. My opinion. Cheers – choquero70 Mar 25 '22 at 06:47
  • It's just that I try to follow best practices as much as possible, because most of the problems I see in software is because they were violated somewhere. But I can totally be pragmatic too, and in this case, it seems to be worth it like you said. Cheers! – AmsterdamLuis Mar 25 '22 at 14:31
0

Don't use database related dependencies inside the hexagon.

The idea is to decouple the business logic from the user interface and infrastructure. Database logic should be placed into an adapter.

It theory it sounds great, in practice that means tons of mappers i.e. boilerplate code. On the bright side you have a Kotlin, and not a Java project so this should be a bit less tedious than the alternative. Bear in mind that there are projects such as Dozer, MapStruct that can make the mapping process easier.