Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entities shouldn't depend on database? #5

Open
rongi opened this issue Mar 22, 2018 · 5 comments
Open

Entities shouldn't depend on database? #5

rongi opened this issue Mar 22, 2018 · 5 comments

Comments

@rongi
Copy link

rongi commented Mar 22, 2018

Your entities looks like database object, they have table names, database ids, etc. Aren't entities supposed to be most abstract type of data, not dependent in any way on your persistence solution?

http://cleancodejava.com/uncle-bob-payroll-case-study-full-implementation/

"Entities are not the same as JPA Entities, they are high level business rules, policies, and should be independent from any other concerns."

It looks like entities here are JPA Entities.

@mp911de
Copy link
Owner

mp911de commented Mar 22, 2018

Thanks for raising this issue. Not entirely sure we're talking about the same here. Entities (business objects) like Item are decoupled from JPA entities (such as ItemEntity).

There's a similarity between Item and ItemEntity as they represent the same business data and there's no need for a fancy application model that makes it hard to correlate with its persistent representation. The application model does not contain table names, database ids and such.

Care to elaborate further on:

Your entities looks like database object, they have table names, database ids, etc. Aren't entities supposed to be most abstract type of data

That's the bit I'm currently not following.

@rongi
Copy link
Author

rongi commented Mar 22, 2018

Thank you for your answer Mark. It's clear now. I thought that Item objects are models, because they are inside applicationmodel package, and ItemEntity objects are entities because they are inside entity package.

Now it's clear that Item is an entity and ItemEntity is a database object. Do you think it's a good idea to rename the packages to prevent that kind of confusion in the future?

@mp911de
Copy link
Owner

mp911de commented Mar 22, 2018

In general, there a few terms to describe the same thing and overlapping terms. Talking about an entity without further context lets one think about JPA entities. Entities within the hexagonal architecture are a different thing.

I'm happy to improve. In general, one wants to have a properly named application model without prefixes/suffixes as that's where a fair amount of focus lies on. I used …Entity within the JPA module to distinguish between the application model entity and JPA entity lacking creativity 🙃

Do you have a suggestion how to improve naming?

@rongi
Copy link
Author

rongi commented Mar 22, 2018

I like the class naming. I'm talking about renaming the java packages where the classes are located. applicationmodel -> entity, entity -> jpaentity or dbmodels or something like that.

@mp911de
Copy link
Owner

mp911de commented Mar 22, 2018

applicationmodel -> entity

Makes sense.

entity -> `jpaentity``

Moving all classes and interfaces to their parent package (.jpa) might be even the better way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants