Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java domain objects shared between projects

Tags:

java

spring

maven

I have two Java projects with same domain objects.First project is the administration of a webapp. And second project is the webapp.

I've chosen this approach in order to allow deployment of administration without downtime for my webapp.

So both projects use same database. I'm using spring-data and marking entities with @Entity.

My question is: is there any way to replicate domain objects in each project? For example creating another maven module with the domain objects and mark as a dependency. (But in this case @Entity will still work?).

like image 353
ilopezluna Avatar asked Nov 28 '25 09:11

ilopezluna


1 Answers

the way is just as you said it - create a maven module (usually called datamodel, infomodel or something along those lines) that contains all of your JPA classes (@Entity classes).

this model can either be a completely separate 3rd project (more work) or, more likely, pick one of the 2 projects as the "owner" of the module and the other project will simply list it as a dependency. in both cases you'll need to think about things like version compatibility (what happens when you update administration but not the webapp and the entities changed? who updates the database, how do you make sure the older code can still read/write it?)

as for working, JPA classes work just fine in their own jar.

like image 108
radai Avatar answered Nov 29 '25 22:11

radai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!