2

I want to specify join type on two hibernate entities

`
@Entity
@Table(name = "b_template_control")
public class TemplateControl {
    @Column(name = "id")
    private Long id;

    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.DETACH)
    @JoinColumn(name = "back_validation_id", nullable = false, insertable 
    = false, updatable = false)
    private ValidationRuleBack validationRuleBack;
}
`

as you can see we have @ManyToOne relation, by default hibernate creates INNER JOIN query but I need LEFT JOIN. The question is how could I specify join type using annotations.

Answer It is nullable = false, so how would a left join be different from an inner join?

3
  • 1
    It is nullable = false, so how would a left join be different from an inner join? Commented Jan 5, 2018 at 9:54
  • Actually that was a problem, thanks. For future I want to ask, about existing of annotations to specify Join type. Are those exist? Commented Jan 5, 2018 at 10:14
  • If you let the eager fetch do the work then hibernate will determine the join type automatically. If you write the query yourself (and probably also use lazy fetching) you can specify the join type yourself. But how to would depend on what you use to query: Native SQL query, HQL, JPA Criteria API query or hibernate criteria all have there own way of how to denote joins and fetch types. Commented Jan 5, 2018 at 11:24

1 Answer 1

3

Please refer the following link.

https://docs.jboss.org/hibernate/core/3.3/api/org/hibernate/FetchMode.html

The join type FetchMode implies, the query will be using an outer join

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.