Skip to content

Conversation

@thomasdarimont
Copy link
Contributor

We now support loadgraph / fetchgraph QueryHints on repository query methods, which are applied when a JPA 2.1 capable JPA implementation is used, otherwise they are ignored.

FetchGraphs / LoadGraphs can now be defined on the Entity via the @NamedEntityGraphs annotation.

@Entity
@QueryEntity
@NamedEntityGraphs(@NamedEntityGraph(name = "GroupInfo.members", attributeNodes = @NamedAttributeNode("members")))
public class GroupInfo {
...
@ManyToMany List<GroupMember> members = new ArrayList<GroupMember>(); //default fetch mode is "lazy".
}

The entity graph "GroupInfo.members" overwrites the fetch-mode of the members collection to be "eager".

The fetch graph to be used can now configured on a repository query method.

@Repository
public interface GroupRepository extends CrudRepository<GroupInfo, String> {

    @QueryHints(@QueryHint(name = "javax.persistence.fetchgraph", value = "GroupInfo.members"))
    GroupInfo getByGroupName(String name);
}

@thomasdarimont
Copy link
Contributor Author

Since we use the JPA 2.0 API by default it is difficult to test support for JPA 2.1 features.
We should change our test-support to be able to test support for 2.1 features as well.

I tested this with an external project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably make those constants public to be able to use them in repository definitions.

@odrotbohm
Copy link
Member

As per our discussion this morning:

  • add a dedicated @EntityGraph annotation that takes a name and an enum to distinguish between load and fetch graphs. This should internally be translated into the appropriate hint. What's the better default for load vs. fetch?
  • ideally the annotation evaluation is done inside JpaQueryMethod so that we're able to pull up the generic parts into Spring Data Commons' QueryMethod eventually.
  • we should also detect and reject the declaration of entity graphs to be used if we're not running on a JPA 2.1 persistent provider (that should also make it easier to test the inability of that stuff on JPA 2.0)

Thomas Darimont added 5 commits March 28, 2014 12:36
… configuration via JPA 2.1 fetch-groups.

Prepare issue branch.
…fetch-/loadgraph.

We now support loadgraph / fetchgraph QueryHints on repository query methods, which are applied when a JPA 2.1 capable JPA implementation is used, otherwise they are ignored.

FetchGraphs / LoadGraphs can now be defined on the Entity via the @NamedEntityGraphs annotation.

Original pull request: #74.

```java
@entity
@QueryEntity
@NamedEntityGraphs(@NamedEntityGraph(name = "GroupInfo.members", attributeNodes = @NamedAttributeNode("members")))
public class GroupInfo {
...
@manytomany List<GroupMember> members = new ArrayList<GroupMember>(); //default fetch mode is "lazy".
}
```

The entity graph "GroupInfo.members" overwrites the fetch-mode of the members collection to be "eager".

The fetch graph to be used can now configured on a repository query method.
```java
@repository
public interface GroupRepository extends CrudRepository<GroupInfo, String> {

	@QueryHints(@QueryHint(name = "javax.persistence.fetchgraph", value = "GroupInfo.members"))
	GroupInfo getByGroupName(String name);
}
```
…fetch-/loadgraph.

Applied suggestions from code review.
The EntityGraph to use can now be configured on query method level via the new @entitygraph annotation. The new method JpaQueryMethod#getEntityGraph analyses an @entitygraph annotation and constructs a new JpaEntityGraph value object that contains the information form the annotation. The new method AbstractJpaQuery#applyEntityGraphConfiguration tries to apply the given EntityGraph configuration if the used JPA persistence provider supports the JPA 2.1 spec.
Changed the class path order such that EclipseLink is now placed before the eclipse dependency. EclipseLink references the JPA 2.1 API and allows us to provide type-safe support for the new JPA 2.1 features.
…fetch-/loadgraph.

Renamed FetchGraphType to EntityGraphType.
…fetch-/loadgraph.

Added additional test cases.
thomasdarimont pushed a commit that referenced this pull request Mar 30, 2014
…fetch-/loadgraph.

We now support load-graph / fetch-graph QueryHints on repository query methods, which are applied when a JPA 2.1 capable JPA implementation is used. We explicitly reject the usage of those hints in case the user is running a JPA 2.0 provider.

FetchGraphs / LoadGraphs can now be defined on the Entity via the @NamedEntityGraphs annotation.

@entity
@QueryEntity
@NamedEntityGraphs(@NamedEntityGraph(name = "GroupInfo.members", attributeNodes = @NamedAttributeNode("members")))
public class GroupInfo {

  @manytomany List<GroupMember> members = new ArrayList<GroupMember>(); //default fetch mode is "lazy".
}

The entity graph "GroupInfo.members" overwrites the fetch-mode of the members collection to be "eager".

The entity graph to be used can now configured on a repository query method.

@repository
public interface GroupRepository extends CrudRepository<GroupInfo, String> {

	@entitygraph("GroupInfo.members")
	GroupInfo getByGroupName(String name);
}

The new method JpaQueryMethod#getEntityGraph analyses an @entitygraph annotation and constructs a new JpaEntityGraph value object that contains the information form the annotation. The new method AbstractJpaQuery#applyEntityGraphConfiguration tries to apply the given EntityGraph configuration if the used JPA persistence provider supports the JPA 2.1 spec.

Changed the class path order such that EclipseLink is now placed before the eclipse dependency. EclipseLink references the JPA 2.1 API and allows us to provide type-safe support for the new JPA 2.1 features.

Original pull request: #74.
@odrotbohm odrotbohm closed this Mar 30, 2014
@odrotbohm odrotbohm deleted the issue/DATAJPA-466 branch March 30, 2014 14:54
thomasdarimont pushed a commit that referenced this pull request Mar 31, 2014
…fetch-/loadgraph.

We now support load-graph / fetch-graph QueryHints on repository query methods, which are applied when a JPA 2.1 capable JPA implementation is used. We explicitly reject the usage of those hints in case the user is running a JPA 2.0 provider.

FetchGraphs / LoadGraphs can now be defined on the Entity via the @NamedEntityGraphs annotation.

@entity
@QueryEntity
@NamedEntityGraphs(@NamedEntityGraph(name = "GroupInfo.members", attributeNodes = @NamedAttributeNode("members")))
public class GroupInfo {

  @manytomany List<GroupMember> members = new ArrayList<GroupMember>(); //default fetch mode is "lazy".
}

The entity graph "GroupInfo.members" overwrites the fetch-mode of the members collection to be "eager".

The entity graph to be used can now configured on a repository query method.

@repository
public interface GroupRepository extends CrudRepository<GroupInfo, String> {

	@entitygraph("GroupInfo.members")
	GroupInfo getByGroupName(String name);
}

The new method JpaQueryMethod#getEntityGraph analyses an @entitygraph annotation and constructs a new JpaEntityGraph value object that contains the information form the annotation. The new method AbstractJpaQuery#applyEntityGraphConfiguration tries to apply the given EntityGraph configuration if the used JPA persistence provider supports the JPA 2.1 spec.

Changed the class path order such that EclipseLink is now placed before the eclipse dependency. EclipseLink references the JPA 2.1 API and allows us to provide type-safe support for the new JPA 2.1 features.

Original pull request: #74.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants