How can I retrieve the foreign key from a JPA ManyToOne mapping without hitting the target table?

前端 未结 5 897
萌比男神i
萌比男神i 2020-12-29 08:07

I have the following two annotated classes that I use to build a graph:

@Entity
@Table(name = \"Edge\")
public class Edge
{
    /* some code omitted for brev         


        
5条回答
  •  借酒劲吻你
    2020-12-29 08:59

    I think you should try to optimize your query rather than change the mapping. For example, the following query fetches the whole graph at once (tested in Hibernate):

    List nodes = em.createQuery(
                "SELECT DISTINCT n FROM Node n LEFT JOIN FETCH n._rgOutbound")
                .getResultList();
    

提交回复
热议问题