Hi,
OpenJPA provides several options to tune fetch mode [1]. However, the
scenario you describe may not benefit from them. Because, 
a) once OpenJPA eager-joins into a class (i.e. Product.logs), it cannot
issue any further eager to-many joins or parallel selects from that class in
the same query (i.e. ActionLogs.children). To-one joins, however, can
recurse to any level. 
b) when OpenJPA knows that it is selecting for a single object only, it
never uses parallel mode, because the additional selects can be made lazily
just as efficiently.


[1]
http://openjpa.apache.org/docs/latest/manual/manual.html#ref_guide_perfpack_eager




Beniamin Mazan wrote:
> 
> I got Entity with relation to itself like :
> 
> public class ActionLog {
> 
>       @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.REFRESH}, fetch =
> FetchType.EAGER)
>       @JoinColumn(name = "product_id", nullable = false)
>       private Product product;
> 
>       @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.REFRESH}, fetch =
> FetchType.EAGER)
>       @JoinColumn(name = "parent_id", nullable = true)
>       private ActionLog parent;
> 
>       @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy 
> =
> "parent")
>       @OrderBy(value = "created DESC")
>       private List<ActionLog> children = new ArrayList<ActionLog>();
> 
> }
> 
> When I execute named query to load Product with ActionLogs :
> SELECT p FROM Product p LEFT JOIN FETCH p.logs WHERE p.id = :id
> OpenJPA generates strange set of select.
> 
> At first is selects all ActionLogs for specified Product - it's OK. But
> next it build single statement to select children of each ActionLog has
> been found in the first step.
> 
> Couldn't it be made simplier?
> 
> Beniamin
> 

-- 
View this message in context: 
http://n2.nabble.com/Incredible-set-of-statements-tp221053p363440.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to