Skip to content

Instantly share code, notes, and snippets.

@mvodep
Created May 2, 2021 16:00
Show Gist options
  • Save mvodep/fddd4a0f37879aff956c99320960d62d to your computer and use it in GitHub Desktop.
Save mvodep/fddd4a0f37879aff956c99320960d62d to your computer and use it in GitHub Desktop.
List<Integer> nodeIds = session.createSQLQuery("SELECT get_graph(3)").list();
MultiIdentifierLoadAccess<NodesEntity> multiLoadAccess = session.byMultipleIds(NodesEntity.class);
List<NodesEntity> nodes = multiLoadAccess.multiLoad(nodeIds);
for (NodesEntity node:nodes) {
System.out.println(node.getNodeName());
for(EdgesEntity edge : node.edges) {
System.out.println(String.format(" %s (%d) -> %s (%d) %s",
edge.getFromNode().getNodeName(),
edge.getFromNode().getId(),
edge.getToNode().getNodeName(),
edge.getToNode().getId(),
edge.getType()));
}
}
/*
Hibernate:
select
nodesentit0_.id as id1_1_0_,
nodesentit0_.node_name as node_nam2_1_0_,
edges1_.from_node_id as from_nod3_0_1_,
edges1_.id as id1_0_1_,
edges1_.id as id1_0_2_,
edges1_.from_node_id as from_nod3_0_2_,
edges1_.to_node_id as to_node_4_0_2_,
edges1_.type as type2_0_2_,
nodesentit2_.id as id1_1_3_,
nodesentit2_.node_name as node_nam2_1_3_
from
playground.nodes nodesentit0_
left outer join
playground.edges edges1_
on nodesentit0_.id=edges1_.from_node_id
left outer join
playground.nodes nodesentit2_
on edges1_.to_node_id=nodesentit2_.id
where
nodesentit0_.id in (
?, ?, ?, ?
)
C
C (3) -> J (10) parent
C (3) -> A (1) parent
J
J (10) -> C (3) child
A
A (1) -> B (2) parent
B
B (2) -> C (3) parent
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment