As per recommended practices documented for DDD or Hexagonal architecture - The domain Model should be separate from the data model representations that are more tied with actual technology used( table/column names, joins, etc, JPA annotation). A practical issue here is - how do you do things like optimistic version control in this model? Say you have a domain service that does read-->update-->save on a domain model. Now the JPA entity might have a version column that it can't pass upwards. Thus when the save call comes to the repo and the repo essentially once again does ( model --> entity) conversion and read+update, it will have no way to tell which version of the entity was read originally.
A secondary issue is the perf consideration of this involving a few extra reads here
Jpa Entity as Domain Model
1.1k views Asked by redzedi At
2
There are 2 answers
0
Utkarsh Sharma
On
There are different ways to do it. It mostly depends on where your application/layer lies in the architecture. Most time the application/layer that communicated with the entity model is at the foundation level. You are not obliged to create a separation when that serves no purpose. The proof of communication will be always the layer that will talk to this layer hence I do not see a need of creating one more transition. You could just pass the entity model/instance data.
Related Questions in JPA
- Hibernate SQL Error: Missing FROM-clause entry for table "th1_1"
- JPA Hibernate OneToOne Mapping
- Problem While Fetching the Entity data and its related Entity data with JPA(Lazy Initialization Exception)
- Why does Hibernate execute two SELECT queries instead of one when using @ManyToOne(fetch = FetchType.EAGER)
- JPA Two primary key at owning side and One Foreign Key at the Child
- Approaches to persist enum in java
- Problem with inserting objects into database that have composite ids
- Unique index or primary key violation Spring JPA
- Concurrently open statements
- JPA SPECIFICATION WITH INTERFACE PROJECTIONS
- Conditional uniqness
- Spring JPA + Hibernate + Rest services + long time transactions
- JPA/Hibernate JpaSystemException: identifier of an instance of X was altered from Y to Z
- How to Revert Database Changes Made in a Session Without Using Transaction Management?
- Hibernate generic type handling
Related Questions in DNS
- AWS Dns record A not navigate to elb
- I created a domain name from cloudflare, and Hoisted my static site hosted in google firebase, error in adding custom domain in firebase
- I am the domain admin, newbie, how do I connect youtube.com on my domain?
- The problem with raising the DNS server on Ubuntu 20.04 - bind9
- I registered a service in eureka which is resolving through java code. But it is not able to resolve its name when hitting through chrome or postman
- Assigned A record for Subdomain in Cloud DNS to Compute Engine VM instance but not propagated/resolved yet
- Why Bind9 responds with latency for RPZ rule?
- Create aws certification for domain
- Make Bind DNS server to request only root DNS servers of IANA website
- Domain Still Redirecting Despite Transferring Out of Godaddy
- Set up MX records in apache/Ubuntu to point to external mail server
- Changing AWS registred domain back to AWS name servers
- Docker networking forwarding failed
- Can access IP address of domain via mobile but not wifi
- CURL got Could not resolve host: my subdomain
Related Questions in DOMAIN-DRIVEN-DESIGN
- How to use Interfaces in Domain Modelling DDD
- Domain driven design CQRS with multiple aggregates and bounded context
- Need more parameters in subclass overridden method
- Domain Driven Design: Aggregates Creating Aggregates
- How to deal with objects creation per request with high RPM node applications
- Async integration events needed sync
- In DDD where to handle interaction with external services that is part of business logic? In Domain Model or in Command Handler?
- How to split large time-related aggregates in DDD?
- One column with foreign key to multiple tables inf EntityFramework Core
- DDD & Clean Architecture: Why not define repositories in the application layer?
- Domain driven design: How to add a new database entry for an Aggregate?
- Integrate a versioning in aggregate
- when to pass args to the constructor of a service in ts?
- ASP.NET boilerplate module's dbcontext recreate abp main tables
- What's wrong with multiple entities in multiple bounded contexts pointing to the same identity?
Related Questions in ONION-ARCHITECTURE
- Creating a User entity while decoupling ASP.NET Core Identity from the Domain layer according to Onion Architecture
- Can a layer method call another method on the same layer in an onion architecture?
- How to work with many to many relationships in ASP.NET Core MVC web app
- How to correctly establish the type argument to CancellationToken in Net Core?
- Why does this ArchUnit test fail?
- What problem of Layer Architecture really solve Onion Architecture?
- Decoupling Identity from Data layer in Onion Architecture in Dotnet Core
- how to fix "Error CS0535 'ApplicationUserManager' does not implement interface member 'IApplicationUserManager.NormalizeKey(string)' "
- Where layer should I put my ViewModel for ASP.NET Core 6
- How to set relationship between entites in clean architecture?
- Clean Architecture in NET Framework 4.5 / 4.7.2
- NUnit tests failed with FLuentValidation in ONion Architecture
- FLuentValidations doesn't work in Onion (Clean) Architecture
- Setup JWT from headers to be used by default in HttpClient
- Appwrite - CRA App template with DI, onion-architecture
Related Questions in HEXAGONAL-ARCHITECTURE
- How to test a Spring method for adding a file to GridFS with JUnit and Mockito?
- Kafka streams in hexagonal architecture
- Access cookies from another service
- Multiple Hexagonal architecture with sprint boot
- Hexagonal Architecture for a Game
- Hexagonal architecture/Ports and adapters: Communication between adapters
- Multi-adapter port in Hexagonal Architecture
- how to reference foreign key in Entity when separating domain model from persistence model
- What is the exact benefits on using Ports/Adapters in hexagonal architecture?
- Where does cache lie in clean architecture
- DDD - Managing "User" entity between aggregates
- H3 Geospatial Index's Projection and Aperture Selection
- Dealing with JPA relationships in hexagonal architecture
- Spring application events without extending ApplicationEvent
- Spring Boot: Use incoming access token for outgoing requests. (Internally pass access token from RestController to Component.)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
You can do different things:
There's no silver bullet solution for a concrete usage of DDD into a project. It depends on your needs and desires.
Should I finish fast? Can I invest a bit of time in a persistence to domain transformation layer?
Is this code used/changed by someone later, that can do weird things if I don't put 'locks' on it?
Am I trying to create a pure DDD implementation?
Should I relax some rules to slowly introduce the DDD in my project, or to my team?
Interesting reading about JPA and Domain entities: