Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

straight_join in JPA or HIBERNATE

How to use select straight_join ... from ... in hibernate/jpa?

like image 214
Hayi Avatar asked Jan 10 '23 03:01

Hayi


2 Answers

There is no straight_join for JPQL/JPA.

You will need to use it in NativeQuery.

entityManager.createNativeQuery(...);

like image 126
uaiHebert Avatar answered Jan 16 '23 05:01

uaiHebert


It should be possible in the Hibernate 5.2.12 and MySQL version 8 using optimizer hint JOIN_FIXED_ORDER (the same effect as STRAIGHT_JOIN) More information available under the links:

Jira ticket: https://hibernate.atlassian.net/browse/HHH-11906

Hibernate code change that allows this: https://github.com/hibernate/hibernate-orm/commit/72506a6eacc367297a3205f6e1fec7ccbc153799

Documentation for MySQL Optimizer hints: https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html

like image 21
mbarabasz Avatar answered Jan 16 '23 05:01

mbarabasz