JPA's EntityGraph feature is cumbersome to define and use. Hibernate 5.4 adds 2 new features to help make working with EntityGraphs easier.
*EntityGraph parsing* The first feature is the ability to create a graph from a String representation. E.g., given a Person entity, we might want to make sure the Person's spouse is eagerly fetched: ```` final EntityGraph eg = org.hibernate.graph.EntityGraphs.parse( Person.class, "spouse", entityManager ); final Person personAndSpouse = entityManager.find( Person.class, 1, Collections.singletonMap( "javax.persistence.fetchgraph", eg ); ```` This parsing supports all of the features of EntityGraph creation including sub-graphs (though see second feature) and sub-class graphs. See the documentation for in-depth discussion and examples. *EntityGraph manipulation* This is mainly about combining graphs. E.g. ```` final EntityGraph eg1 = org.hibernate.graph.EntityGraphs.parse( Person.class, "spouse", entityManager ); final EntityGraph eg2 = org.hibernate.graph.EntityGraphs.parse( Person.class, "spouse(age, dob)", entityManager ); final EntityGraph combinedGraph = org.hibernate.graph.EntityGraphs#merge( entityManager, Person.class, eg1, eg2 ) final Person personAndSpouse = entityManager.find( Person.class, 1, Collections.singletonMap( "javax.persistence.fetchgraph", combinedGraph ); ```` This is a very trivial example meant just for illustration. It can actually be much more easily defined as: ```` final EntityGraph combinedGraph = org.hibernate.graph.EntityGraphs.parse( Person.class, "spouse( age, dob )", entityManager ); final Person personAndSpouse = entityManager.find( Person.class, 1, Collections.singletonMap( "javax.persistence.fetchgraph", combinedGraph ); ```` P.S. Looking back at this, I wonder if we want to combine `org.hibernate.graph.GraphParser` into `org.hibernate.graph.EntityGraphs`. As-is, users wanting to use both of these features above would need to import both of those classes. What do y'all think? On Mon, Nov 5, 2018 at 5:41 PM Steve Ebersole <st...@hibernate.org> wrote: > With regard to entity graphs, the only new piece is the "parse a string > representation" feature. I'll write up a release notes blurb with a simple > code sample, but the new documentation sections cover this feature very > in-depth. > > > > On Mon, Nov 5, 2018 at 12:07 PM Guillaume Smet <guillaume.s...@gmail.com> > wrote: > >> Hi, >> >> If everybody is OK with it, I would like to wrap 5.4.0.CR1 on Wednesday >> 14th (this is next Wednesday). >> >> That means that everything we want in 5.4.0 should be in by then. >> >> The big remaining subject IMHO is this one: >> https://github.com/hibernate/hibernate-orm/pull/2611 . I think we really >> need that in. >> >> Chris, Gail, do you think you can drive this puppy home before then? >> >> If you have issues affected to you that you know won't be fixed before >> next >> Wednesday, can you please move them to 5.4.1 so that we have a clear >> vision >> of the remaining work? >> >> Steve, could you please prepare a paragraph about the entity graph work >> for >> the announcement? As it's the big new feature of this release, some code >> showing the improvements made would be welcome, I think. >> >> Thanks! >> >> -- >> Guillaume >> _______________________________________________ >> hibernate-dev mailing list >> hibernate-dev@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/hibernate-dev >> > _______________________________________________ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev