aspose file tools*
The moose likes Spring and the fly likes Active record vs Sping-data jpa with Roo Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Active record vs Sping-data jpa with Roo" Watch "Active record vs Sping-data jpa with Roo" New topic
Author

Active record vs Sping-data jpa with Roo

Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1666
    
    7

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,

[How To Ask Questions][Read before you PM me]
Ken Rimple
author
Ranch Hand

Joined: Jul 20, 2010
Posts: 63

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).


Ken Rimple
ken.rimple@gmail.com
Co-author, Manning Spring Roo in Action
I teach for Chariot Solutions (Spring, Maven, Hibernate, other courses). Schedule here
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1666
    
    7

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Active record vs Sping-data jpa with Roo