The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Hastybit (1) [Avatar] Offline
#1
Class Diagram
[ 1018 KB ]
Hello, John! First of all you have written a very good book, but while reading it i had some questions related to part one and two.

I have attached some image with data model of my pet project. I am going to use Hibernate as ORM solution and there is the problem or it is my misunderstanding. My questions are:

1. Can all services use one db and same db schema where located all entities as tables?

2. How should i manage my entities relationships (associations) like OneToOne, ManyToMany, OneToMany etc? For example - If my Donations service exposes creatateDonation operation and there is data that is dependent on Activity. Is it good to make separate call to Activity services operations to avoid direct change data via Hibernate in Activity table?

3. Is it right to get separate calls to some services to get all information from db? For example - I want to get all activities by user and user info too. The call should look like:

User user = UserService.getUserById(userId) - // Can this method return User with associated entities of Activity ? Or i should do another call like
List<Activity> activities = ActivityService.getActivities(user.getId())
return someView.with(user).withActivities(activities)

Hope you understand my questions and will try to clear my mind about these issues.
Thank you!
John C Carnell (44) [Avatar] Offline
#2
Hi HastyBit,

Sorry it took me so long to get back to you. I have been heads down finishing the book and remiss in keeping up with my posts smilie.

See my comments below>

Hello, John! First of all you have written a very good book, but while reading it i had some questions related to part one and two.

I have attached some image with data model of my pet project. I am going to use Hibernate as ORM solution and there is the problem or it is my misunderstanding. My questions are:

1. Can all services use one db and same db schema where located all entities as tables?

That is really up to you and your organization. I have seen some orgs use separate databases. However, if you do not want to do that most of the time I see one service/schema with a specific service id used to access the data, This way access control is enforce and prevents a developer and just doing a quick join over to your table to pull down data.

2. How should i manage my entities relationships (associations) like OneToOne, ManyToMany, OneToMany etc? For example - If my Donations service exposes creatateDonation operation and there is data that is dependent on Activity. Is it good to make separate call to Activity services operations to avoid direct change data via Hibernate in Activity table?

Usually you are going to group related data tables to together. In your example you would have your donation service manage the work and then use the activity service to retrieve or update the dependent data. Microservice architectures tend to proliferate data elements and often times you are are going to do a lot more database calls then you would with a traditional application because you want to enforce boundaries in the service. At my company we often use caching to help alleviate the pressure on the database (from repeated calls).

3. Is it right to get separate calls to some services to get all information from db? For example - I want to get all activities by user and user info too. The call should look like:

User user = UserService.getUserById(userId) - // Can this method return User with associated entities of Activity ? Or i should do another call like
List<Activity> activities = ActivityService.getActivities(user.getId())
return someView.with(user).withActivities(activities)

Again if the domain objects are closely related (have high cohesion then I would consider lumping them into one service. Hope that makes sense
Hope you understand my questions and will try to clear my mind about these issues.
Thank you!