Hibernate HQL: Left Join with OnetoOne

Ascalonian

I have the following entity caled Product:

@Id 
@SequenceGenerator(name = "Product_seq", sequenceName = "PRODUCT_SEQ", allocationSize = 1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "Product_seq")
@Column(name = "ID")
private Long id;

@OneToOne
@JoinColumn(name = "CAS_ID")
private CAS cas;
...

And a CAS entity:

@Id
@SequenceGenerator(name = "CAS_seq", sequenceName = "CAS_SEQ", allocationSize = 1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "CAS_seq")
@Column(name = "ID", unique = true, nullable = false, scale = 0)
private Long id;

@Column(name = "CAS_NUMBER", length = 6)
private String casNumber;

@Column(name = "CAS_DESCRIPTION")
private String casDescription;
...

In my application, I have the following HQL statement:

select p from Product p where p.approve IS NULL order by p.cas.casNumber desc

The issue here is that p.cas.casNumber can be NULL and I need to return those rows as well. I am not sure how to write the LEFT JOIN on this table using the p.cas.casNumber.

I appreciate any of the help you can provide. Thank you!

nayakam

You could try as follows:

select p from Product p left join p.cas as a where p.approve IS NULL order by a.casNumber desc

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Hibernate LEFT JOIN HQL query not counting correctly with condition

From Dev

Hibernate HQL from child to parent table using left join

From Dev

Hibernate @OneToOne join column

From Dev

grails hql left outer join

From Dev

HQL: Combine Left and Right Join

From Dev

grails hql left outer join

From Dev

Hibernate chokes on this HQL cross join

From Dev

Hibernate HQL: is JOIN really necessary?

From Dev

Hibernate does multiple queries on @OneToOne join

From Dev

HQL equivalent for additional conditions in LEFT JOIN

From Dev

Hibernate HQL join fetch not recursively fetching

From Dev

Hibernate fetch=join/select is not applicable for HQL?

From Dev

Hibernate HQl to join two level tables

From Dev

How to query join one to many in hibernate HQL

From Dev

Hibernate Criteria Left Excluding JOIN

From Dev

Hibernate @OneToOne executes multiple queries even with @Fetch(FetchMode.JOIN)

From Dev

DOT node with no left-hand-side using HQL with join

From Dev

Oracle left-outer-join syntax shorthand notation (+) available in HQL?

From Dev

Oracle left-outer-join syntax shorthand notation (+) available in HQL?

From Dev

Hibernate HQL bulk delete don't remove join table values

From Dev

Hibernate: HQL join query on association doesnt result as expected

From Dev

Hibernate HQL bulk delete don't remove join table values

From Dev

Hibernate: HQL join query on association doesnt result as expected

From Dev

Hibernate criteria using left join to filter results

From Dev

Hibernate generates a "on ... and null=null" on left join

From Dev

Hibernate generates a "on ... and null=null" on left join

From Dev

Hibernate criteria using left join to filter results

From Dev

Hibernate: Multiple condition on LEFT JOIN using a criteriaBuiler

From Dev

Hibernate ManyToOne vs OneToOne

Related Related

  1. 1

    Hibernate LEFT JOIN HQL query not counting correctly with condition

  2. 2

    Hibernate HQL from child to parent table using left join

  3. 3

    Hibernate @OneToOne join column

  4. 4

    grails hql left outer join

  5. 5

    HQL: Combine Left and Right Join

  6. 6

    grails hql left outer join

  7. 7

    Hibernate chokes on this HQL cross join

  8. 8

    Hibernate HQL: is JOIN really necessary?

  9. 9

    Hibernate does multiple queries on @OneToOne join

  10. 10

    HQL equivalent for additional conditions in LEFT JOIN

  11. 11

    Hibernate HQL join fetch not recursively fetching

  12. 12

    Hibernate fetch=join/select is not applicable for HQL?

  13. 13

    Hibernate HQl to join two level tables

  14. 14

    How to query join one to many in hibernate HQL

  15. 15

    Hibernate Criteria Left Excluding JOIN

  16. 16

    Hibernate @OneToOne executes multiple queries even with @Fetch(FetchMode.JOIN)

  17. 17

    DOT node with no left-hand-side using HQL with join

  18. 18

    Oracle left-outer-join syntax shorthand notation (+) available in HQL?

  19. 19

    Oracle left-outer-join syntax shorthand notation (+) available in HQL?

  20. 20

    Hibernate HQL bulk delete don't remove join table values

  21. 21

    Hibernate: HQL join query on association doesnt result as expected

  22. 22

    Hibernate HQL bulk delete don't remove join table values

  23. 23

    Hibernate: HQL join query on association doesnt result as expected

  24. 24

    Hibernate criteria using left join to filter results

  25. 25

    Hibernate generates a "on ... and null=null" on left join

  26. 26

    Hibernate generates a "on ... and null=null" on left join

  27. 27

    Hibernate criteria using left join to filter results

  28. 28

    Hibernate: Multiple condition on LEFT JOIN using a criteriaBuiler

  29. 29

    Hibernate ManyToOne vs OneToOne

HotTag

Archive