#Modular Monolith Spring Boot Entity decoupling issue

1 messages · Page 1 of 1 (latest)

devout sphinx
#

I am trying to refactor my monolith app to modular monolith. Everything goes smooth until I faced this. (I am not using Spring modulith for now because 1st I want to slice everything in independent modules then I will add it).
I have 2 Entity classes which belongs to 2 different modules:
Module Task: Task entity
Module Space: Space entity

@Table(name = "tasks", schema = "public")
public class Task {
   
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "space_id", nullable = false)
    private Space space;

    //rest of the code

So I shouldn't have access to Space class in Task module because Space doesn't belong to Task module. How should I resolve this? I need to have this @ManyToOne relationship with Space in Task. Should I create new Space entity in Task module or? How are you guys solving those issues?

turbid whaleBOT
#

<@&987246841693360200> please have a look, thanks.

gilded harness
#

modular microservices work with their own databases

#

there are no foreign key constaints

#

you can store an id of a related entity, then query the other service using REST

devout sphinx
#

But I am not building microservices. I am buidling modular monolith. I mean I am trying to refactor this monolith in modular monolith. As far as I understood modular monolith are still one application which has independent modules. Shouldn't be different from microservices?

sly vine
#

When using modulith each domain is standalone. Thus you should only map the key.

#

Mapping the full entity in this case would seeminly cross your domain.

devout sphinx
sly vine
#

You shouldn't even have a defined FK.

devout sphinx
# sly vine You shouldn't even have a defined FK.

Thanks for clarification man. Few more questions if you are able to answer I would really appreciate.
Do I need different databases for modular modulith?
So without FK I am not able to use joins from sql?

sly vine
#

You don't need separate schemas, and you can technically still join on the ID. The FK just enforces the existence.

sly vine
#

You're welcome.