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
- JPA - How to query with a LIKE operator in combination with an AttributeConverter
- How to create nested selects with sql?
- Play Framework Unable to build entity manager factory when Working with PostGIS
- Getting entity with a join table GAE
- Is it necessary to create an repository and a service for each entity?
- JPA, Hibernate can I do composite primary key which one element is foreign kay @OneToMany?
- Hibernate Search Faceting not working
- EntityManagerSetupException for multiple joins and a sub query for NamedQuery
- JPA and web app
- JPA findDistinctPropertyBy magic method doesn't work as expected when using spring-boot-starter-jpa
- Inject EntityManager in SwitchYard Junit implementation
- QueryDSL where relationship may be null
- JPA, how can i have two queries, one use lazy and one use eager for fetching?
- Duplicate entry '[X]' for key '[Y]' on JPA repository 'save' operation. Saved entity has its key defined already
- Hibernate's bidirectional OneToOne relationship not working within the same class
Related Questions in DNS
- Configured TTL for A record(s) backing CNAME records
- Redirecting subdomain to directory on Azure
- SPF and DKIM records for Mandrill on DigitalOcean
- How to convert hostname to DNS name?
- Could someone bring Google OAuth2 for Cloud DNS via Rest to light?
- Spoof Captive Portal Screen on an iOS Device using DNS
- DNS_PROBE_FINISHED_NXDOMAIN on Google App Engine website
- How to check if a redirect leads to a different domain
- IP address to Domain Name? DNS?
- error CS1729: The type `ARSoft.Tools.Net.Dns.DnsServer' does not contain a constructor that takes `4' arguments
- Windows, Apache, Acrylic DNS, and wildcard subdomains
- How to configure DNS for microsoft odbc driver for oracle (in 64 bit arch.)
- How to use one time domain name in android?
- logstash dns filter miss
- Redirect website to another website if blocked in particular region
Related Questions in DOMAIN-DRIVEN-DESIGN
- Should i take DateTime.Now from Database?
- How to avoid anemic data model? Can repositories be injected into entities?
- Defining aggregate roots when invariants exist within a list
- Is it okay to create a DTO counterpart of a table in a database assuming its persistent ignorant domain model and the DTO is in the repository?
- Should i do authorization on my Domain Services?
- Should i validate if related entity exists before insert?
- Using framework event dispatcher to raise domain event
- How to temporarily circumvent domain object's creation contracts when restoring application from backup?
- Domain Driven Design for Rails App: Implementing a service in a basic example
- DDD\CQRS\Event Sourcing and request historical data
- Is it possible to properly use DDD with all building blocks in monolith application?
- Replicate property size from domain to fluent api and viewmodel
- DDD aware of existance of an entity outside the context?
- Is there a way to access a private property in a where clause?
- Should I unite business domains into one business layer
Related Questions in ONION-ARCHITECTURE
- Onion Architecture Identity Framework
- Where to apply domain level permissioning
- Autofac not working after update
- Mapping Stored Procedures in Onion Architecture
- Authorize with Roles in onion Architecture
- Where does external device logic belong in domain driven design?
- Refactoring to Domain driven design
- Layered Architecture with DI vs onion architecture?
- Onion Architecture, Unit of Work and a generic Repository pattern
- Generic Repository and Leaky Abstraction
- Repository pattern: Deleting the aggregate root
- Mapping a Domain Model to the database with EF Fluent API
- Onion Architecture for Modernization
- Breaking the "ubiquitous language" by having an IoC in Domain Model?
- Loading dependencies in Unity Container in WinForms application
Related Questions in HEXAGONAL-ARCHITECTURE
- Where to apply domain level permissioning
- DDD - Manage Coupling between Domain and Repository
- Work with dto's to build an API with DDD
- Use case containing the presenter or returning data?
- DDD and helper classes
- how to reference foreign key in Entity when separating domain model from persistence model
- Multi-adapter port in Hexagonal Architecture
- Hexagonal architecture/Ports and adapters: Communication between adapters
- Hexagonal Architecture for a Game
- Multiple Hexagonal architecture with sprint boot
- Jpa Entity as Domain Model
- Need an opinion about abstractions and update process in a domain model
- How can I dockerize multi module Spring app?
- Domain Driven Design (DDD): Domain Event Handlers – Where to place them?
- Load object from multiple datasources with hexagonal architecture (ports and adapters)
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: