简体   繁体   中英

Spring Data JPA + openjpa: Is it possible to join a table not in OR-Hierarchy?

So, the following usecase:

I've got two tables and the corresponding entities, lets call them table A (the left) and table B (the right). Both tables have a column "size", but at my OR-Model, table a has no reference to an object of table b. Now what I want to achieve (via Spring Data JPA @Query-Annotation / JPQL, not using native SQL) is something like the following (a little simplified) Query:

@Query("select a from TheLeftTable a join TheRightTable b" +
       "where b.size = a.size ")
Page<TheLeftTable> findAllAvailableEntries(Pageable p);

but i get the following exception cause when trying to start my tomcat:

...Caused by: org.apache.openjpa.persistence.ArgumentException: Encountered "join TheRightTable b" at character 48, but expected: [".", "FETCH", "INNER", "JOIN", "LEFT", ]

So my Question is: Is this generally possible or not to create such a query with JPQL / JPA only? Please remember: In My OR-Model, TableA has no Object from Table B. My simplified Entitiy-Properties are looking just like this:

@Column(name = "size")
String size;

If it is not possible, any other ideas would be great. (Except changing my Entity for Table A to have the object of Entity B, which is sadly not possible)

No problem, it is possible to do that:

SELECT a FROM TheLeftTable a, TheRightTable b WHERE b.size = a.size

It is called cross join, but if the columns size are indexed, you won't notice it any performance issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM