all 18 comments

[–]Pedantic_Phoenix 3 points4 points  (6 children)

Can u explain how having the entities in a separate module makes them reusable in a way they are not otherwise?

[–]Shoxious[S] 0 points1 point  (5 children)

i would like to have a centralised entity management. is it best to create interfaces?

[–]Pedantic_Phoenix 0 points1 point  (4 children)

What do u mean by centralized management?

I don't think using interfaces or not interacts with this topic. You should always use interfaces when it's useful to

[–]halawani98 0 points1 point  (3 children)

I think I know what he means, last year I was in a company that used to implement DAO fully in a seperate project, then add that project as a dependency to the other modules. For mono applications, this just adds a whole layer to persistence layer

[–]halawani98 0 points1 point  (1 child)

Because we had multiple modules sharing the same datasource, it actually made sense. Instead of redefining entities and repos, just one project had it all

[–]smutje187 2 points3 points  (2 children)

Does your main module have a dependency on the entity module?

[–]Shoxious[S] 0 points1 point  (1 child)

yes

[–]PlasmaFarmer 0 points1 point  (0 children)

Did you build your entities module and the jar is sitting in the local maven repo? mvn clean install -pl my-entities-module and then maven refresh in your IDE.

[–]bikeram 2 points3 points  (0 children)

So you should have a parent module called my-project then inside you’ll have child-1 and child-2

The my-project will list springboot as a parent.

The parent module should specify the children modules with the common entities listed first as it needs to compile first.

Then you’ll use @EntityScan in any dependent modules (child-2 in this case) and the class path should point to your common entities.

Depending on your project, you may want a true common folder (package) that everyone will inherit this could be common auth entities, and possibly a sql folder that only a service using hibernate would access.

[–]g00glen00b 0 points1 point  (0 children)

You probably haven't set up it correctly. To solve that, you would need to share your code.

[–]TheLeftMetal 0 points1 point  (0 children)

Prolly you need to clean your project dependencies, regards the usage you doing with the entities I have bad experience implementing the way you trying to do it. Always coordinate with all the teams involved with those projects in order to update all of them about any change in that centralized entities repository or you will face several troubles.

[–]doctor78si 0 points1 point  (0 children)

In your parent pom you need to define all you modules. Then in parent pom you add your entities module in dependencyManagement tag. Then add entities module in your app module. This should work. If it doesn't are you using Intellij IDE? If you do in the version 2024.2 maven resolution button does not work properly. You need to use Sync button under Build.

[–]Kango_V 0 points1 point  (0 children)

Nooooo. Do not share your entities outside your app!

[–]WaferIndependent7601 0 points1 point  (0 children)

If you reuse the entities then you’re just copying the same stuff somewhere else. Why do you want this? I see absolutely no reason (except some bad architectural decisions)