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

前端 未结 5 896
萌比男神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:46

    How about using getReference()?

    For example:

    Node fkNode = em.getReference(edge.getNodeFrom()); // [1]
    fkNode.getId()
    

    [1] This will not trigger a SQL query to retrieve the nodeFrom

提交回复
热议问题