• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Active record vs Sping-data jpa with Roo

 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ken,

I know that Spring Roo has really pushed the active record pattern and I fully understand the argument for it (If you are using Roo). Of course on my projects many developers do not use Roo. I have started pushing spring-data-jpa with quite a bit of success and from what I understand Roo is supporting this now as well. Would you consider the integration between these 2 projects pretty mature at this point or are there still a lot of outstanding issues? Does your book cover this?

Thanks,
 
author
Posts: 63
Mac OS X Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure about the maturity of Spring Data JPA in general, but in terms of integration with Spring it's been available since Roo 1.2.0, close to 6 months.

I would highly recommend that instead of Active Record. I'm not a big fan of it, unless you have a really simple data model, or a quick CRUD application to write. The problem is, everything eventually gets bigger, more complex, and needs multi-entity methods for cross-domain transactions, etc...

So I'm a big fan of this approach:

1. Use services and repositories (hence the Spring Data JPA ones)
2. Use the automatic building of the Spring Data JPA repositories, but then implement a class that you move the annotations to, and add your own methods to that repository.
3. Also, you can feel free to create non-generated repositories for straight JPA methods and key data services. It's Spring after all.

Then there's the question of whether to trust the whole 'session in view' thing, which I'm not a huge fan of but understand why it exists. I would probably begin with exposing the entities (carefully) but then creating DTOs where needed (intermediate calculations, web-only results or information) so you do the 80/20 approach.

Some feel more strongly about the whole DTO -vs- exposing entities thing, and for them I say it depends on the situation but I'd not disagree with creating DTOs. The case can be made for a Roo add-on to generate DTOs based on annotations of the entities.

I fact, think of it, maybe:



Now you've gone and given me an idea... Darn!

(Sorry, my sense of humor involves silly comments - please excuse me for the week).
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks,

I like the idea of the DTO generator, Even better if they can be JaxBAnnotated

We often times ran into the problem where we only cared about the relationships in one direction (at least from the view or service client perspective) and when passing the entities directly vs using DTO it got into some sort of recursive mess loading collections etc and eventually ran out of memory. In this case it was partially due to the design of the database but it was nice to be able to exclude certain fields and collections in some cases in what was returned. So the DTO ended up being a subset of the actual entity object.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic