views:

357

answers:

1

I'm using DataNucleus as a JPA implementation to store my classes in my web application. I use a set of converters which all have toDTO() and fromDTO().

My issue is, that I want to avoid the whole DB being sent over the wire:

  • If I lazy load, the converter will try to access ALL the fields, and load then (resulting in very eager loading).
  • If I don't lazy load, I'll get a huge part of the DB, since user contains groups, and groups contains users, and so on.

Is there a way to explicitly load some fields and leave the others as NULL in my loaded class? I've tried the DataNucleus docs with no luck.

+2  A: 

Your DTOs are probably too fine-grained. i.e. dont plan to have a DTO per JPA entity. If you have to use DTOs then make them more coarse grained and construct them manually.

Recently we have had the whole "to DTO or not to DTO, that is the question" discussion AGAIN. The requirement for them (especially in the context of a JPA app) is often no longer there, but one of the arguments FOR DTOs tends to be that the view has coarser data requirements.

Craig
Do you mean, a set of DTOs to be used by each view? Like a user with no "groups" field to send to view that don't need to know the user's groups, and so on?
Hugo
It really depends on your application and how you are architecting it. You talk about it being a Web application but in the same breath you are concerned about things being sent over the wire. What wire? The wire between the appserver and the database or the logical wire between the view and the model/controller layer, or the wire between a browser AJAX call and the server?
Craig
Mainly, the wire between the browser and server, but I'd also like to reduce the DB <-> java server data getting trasmited as well... I guess lazy loading and using one dto per view works, since when converting the model to , I won't accidentaly lazy-load unnecesary data, and I only send what the view needs. It's more work (lots more classes) but I see no choice. Thanks.
Hugo