darrachequesne / spring-data-jpa-datatables

Spring Data JPA extension to work with the great jQuery plugin DataTables (https://datatables.net/)
Apache License 2.0
450 stars 172 forks source link

how to use specifications to join other table? #90

Closed Mike-the-one closed 4 years ago

Mike-the-one commented 6 years ago

I am facing another problem now :-)

I have a table which stores the orders. The orders table has an 'One to Many' mapping to another table, which stores ordered item, orderItems. For each row of the orderItems, it refers to a row in the Product table. And I have another table which stores product image, the product image table has a foreign key which points to the product. How can I use JPA specifications to join the product image in the query result of the orders?

Something like:

Order -> [orderId, ... orderItems[],...] OrderItem -> [orderitemId, ... product,...] Product -> [productId, productname... ] ProductImage -> [producdImageId, .... productId...]

I am searching on Order table.

thanks!

darrachequesne commented 6 years ago

I'd do another query to retrieve all images with the list of product ids. You could use a JOIN FETCH (ref), but the @OneToMany relationship will make for a big query output I think.

darrachequesne commented 4 years ago

Closed due to inactivity, please reopen if needed.