// Select root (state 1)
Query query = em.createQuery("select s from State s where s.name=:name");
FetchPlan fetch = OpenJPAPersistence.cast(query).getFetchPlan();
fetch.setMaxFetchDepth(15);
fetch.addField(State.class, "incomingTransitions");
fetch.addField(State.class, "outgoingTransitions");
fetch.addField(Transition.class, "toState");
fetch.addField(Transition.class, "fromState");
State qs1 = (State) query.setParameter("name", "s1").getSingleResult();
em.close(); // will not load anything anymore