0

I've read the post MVC With Lazy Loading and i still have some questions:

  1. If we use the 4th choice, which part should be in charge of the transform process? The controller or the service? If we use controller, is it good to introduce @Transactional to controller?

  2. I also see a post that suggested to use different query for different usage. It seems like to use different fetch groups JDO fetchgroup for different purpose. Is it good to use this way?

Thanks.

Community
  • 1
  • 1
xi.lin
  • 3,326
  • 2
  • 31
  • 57
  • @Transactional goes on the Service methods. – kmansoor Apr 19 '14 at 00:59
  • 1
    there's really no clearcut answer, have a look at this post i wrote about this http://blog.jhades.org/open-session-in-view-pattern-pros-and-cons/ – Angular University Apr 19 '14 at 14:04
  • @kmansoor If i just use `@Transactional` on Service methods, then the entity cannot access lazy loading fileds in Controller. – xi.lin Apr 21 '14 at 03:58
  • @jhadesdev Thanks and i've read the post and learned the ideas. I also think that osiv is something that broke the layers. – xi.lin Apr 21 '14 at 04:22

1 Answers1

0

In today's day and age you can and should expose services as REST controllers and return proper domain objects rather than ModelAndView or other such constructs from Spring MVC.

UPDATE: Clarification: There is NO controller class in this approach I am suggesting. Expose Service as @Controller. Expose public methods on service as REST and annotate transnational, authorization etc context on the method. Because from an API point of view this public interface serves all kinds of clients whether it is REST or direct method call.

Also if you have dedicated controllers and services you may see some business logic seeping into your controllers in no time.

I would go to even further and not use option 4 which is essentially leads to a DTO anti-pattern.

Having said that it still depends on the complexity of entities. A very complex entity with many association is going to be a performance hog due to the queries it fires. Yet your MVC (JSPs) may actually resolve the associations whenever needed. (In a side note with full REST full architecture this is an issue.)

bhantol
  • 9,368
  • 7
  • 44
  • 81
  • I'm agree that today we should use REST services. And this is also my intention. However, i still have the problem of lazy loading so that i have to use `@Transactional` in controller. – xi.lin Sep 23 '14 at 06:47
  • I am saying that there is no controller class. Expose your service as controller. `@Transactional` should on that method on the service. – bhantol Sep 23 '14 at 20:49
  • Got it, it seems to be a solution. – xi.lin Sep 27 '14 at 02:59