Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
182 views
in Technique[技术] by (71.8m points)

java - Is it necesary to use ManyToOne/OneToMany annotations on microservice arquitecture projects with Spring boot?

I'm creating this project were i have to create views using different entities from different schemes, as microservices do. It is my first microservice project. Is it necessary to use those relations annotations, even when i have to cross info manually with the rest controllers?

question from:https://stackoverflow.com/questions/65892590/is-it-necesary-to-use-manytoone-onetomany-annotations-on-microservice-arquitectu

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think the best answer is it depends. And there is no right or wrong answer.

Basically a microservice encapsulates the business logic specific to a domain (order, email, user, etc).

Generally speaking it is a good idea to have a separate database for each microservice in order to have better decoupling.

If that database, for a clear reason, is a relational database (it can be any database) and the JPA is becoming helpful (defining relations, having transactions, etc.) then you should definitely use them. An alternative could be to use directly the JDBC.

In a microservice architecture you basically lose the transactionability and to achieve a something similar is by far more difficult.

Keep in mind that microservices add a lot more complexity to your projects, in all aspects.

With this context in mind, coming back to your question, you should use it if you need it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...