12

If you have this entity:

@Entity
public class A {

    @ManyToOne
    @JoinColumn(name = "bField", nullable = true)
    private B myBObject;

}

And I have a generic generator of Criteria who will do that:

Root<A> root = criteria.from(A.class);
root.get("myBObject").get("aFieldInB");

The problem is the following: the generated sql will contains a CROSS JOIN between A and B. But I would like that the generated sql will contains a LEFT JOIN between A and B.

How can I do that?

user1180339
  • 319
  • 1
  • 6
  • 16

1 Answers1

2

You must use a join(). In general it is better to always use a join() for relationships.

See, http://en.wikibooks.org/wiki/Java_Persistence/Criteria#JoinType

James
  • 17,965
  • 11
  • 91
  • 146
  • 3
    Yes I know. But as I said, I have a engine to generate my criteria. And this engine receives a Class object (Root) and a String of the path ("myBObject.aFieldInB"). The path cannot be predicted! – user1180339 Apr 10 '13 at 13:50