Announcement Announcement Module
Collapse
No announcement yet.
Custom fetch groups with Spring Data JPA...possible? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom fetch groups with Spring Data JPA...possible?

    I'm a new and very appreciative user of Spring Data JPA, huge fan. But I've hit a wall and I'm looking for guidance.

    I need to be able to use custom fetch groups (or fetch plans, or fetch profiles...heard them called different things). I make use of fetch=FetchType.LAZY on most of my relationships to avoid eagerly fetching deep object graphs in the default case. But I have numerous cases where I need to control which fields are fetched on various entities.

    OpenJPA seems to support this by virtue of "Custom Fetch Groups" -- http://openjpa.apache.org/builds/1.0...ide_fetch.html

    I'm wondering if Spring Data JPA supports this in some way, or if that's on the roadmap (and how far down the road...). It would be an immensely valuable feature imho, being able to tackle this in a vendor-agnostic way. If support for that exists already, can you slap me on the head and point me in the right direction?

    Thanks!

    Dan Checkoway

  • #2
    I've been doing more reading/learning since posting this, and I'd like to refine my question... :-)

    Let's say I have:

    @Transactional(readOnly = true)
    public interface AccountRepository extends JpaRepository<Account, Long> {
    List<Account> findByCustomer(Customer customer);
    }


    Is it possible simply to declare a Fetch argument to the find* methods in my repository interface, i.e.:

    @Transactional(readOnly = true)
    public interface AccountRepository extends JpaRepository<Account, Long> {
    List<Account> findByCustomer(Customer customer); // uses the default fetch
    List<Account> findByCustomer(Customer customer, Fetch fetch); // use the specified fetch
    }


    Something like that?

    Comment


    • #3
      We're currently not supporting this as fetch groups are not specified in JPA 2.0 and we don't want to get into the hassle of writing code for specific persistence providers. There's already quite a few corners where have to work around quirks of the providers despite the JPA . JPA 2.1 will probably include fetch groups so we will add that as soon as the spec is in shape.

      Comment

      Working...
      X