This is how you fetch DTOs efficienctly from the database.https://vladmihalcea.com/the-best-way-to-map-a-projection-query-to-a-dto-with-jpa-and-hibernate/ …
-
-
Prikaži ovu nitHvala. Twitter će to iskoristiti za poboljšanje vaše vremenske crte. PoništiPoništi
-
-
-
DTO projections are nice, but there's more than SELECTs. E.g. you might want to return the current status after applying a write (insert with generated id, updated model). Re in-efficient: do you have actual numbers? Overhead of code-generation based mappers is very, very low.
-
That's not the use case presented in the article.
- Još 5 drugih odgovora
Novi razgovor -
-
-
I'd argue that exposing entities (mapped in a DTO or not) in a restful API is the problematic part.
-
In reality, the business logic might hide the data access layer internal structures. So, the REST API will focus on how data is best consumed by clients rather than just exposing database tables or views over those.
- Još 7 drugih odgovora
Novi razgovor -
-
-
DTOs bypass the first level cache, isn’t it?
-
You make it sounds as if it were a problem
- Još 16 drugih odgovora
Novi razgovor -
-
-
Sure DTOs can be fetched directly too and it's great. But a common problem is that people map the same managed entities directly to JAX-RS endpoints
: this article provides a good alternative. Also people aren't limiting this to neither "read-only" nor "projections"
, so... -
..so we need to provide some guidance. Also while DTO's might be suitable in some cases, there's other in which one benefits from dealing with managed objects in the business layers, before producing an output model exposed on the REST API. At least decouples from API model

- Još 3 druga odgovora
Novi razgovor -
-
-
Agreed, we use this every day. But what about writes? Eg. Ui layer for configuring enterprise applications. This is heavy db oriented setup. A new codelist has many codelist items. Each item has many details. Flat DTOs lack these relations. A mapper is needed. Am i wrong?
-
For writing data, entities are very convenient. That's the main advantage of JPA over other frameworks. DTOs are for reading subsets of data.
- Još 3 druga odgovora
Novi razgovor -
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.