Spring Data - Paging parameters being ignored - spring

I have an issue where paging is not being considered in calls to a PagingAndSortingRepository. In the below call, the list returned is of size 3 (this page_size + 2 is consistent no matter what page size I specify), and the first page is always returned.
The database has 10 elements at time of testing
PageRequest page = PageRequest.of(1, 1);
List<Review> reviews = reviewRepository.findOwner(id, page).toList();
findOwner()
#Query( value = "SELECT r FROM Review r INNER JOIN FETCH r.owner WHERE r.owner.id IN (:ids)",
countQuery = "SELECT COUNT(*) FROM Review r INNER JOIN r.owner WHERE r.owner.id IN (:ids)")
List<Review> findByOwner(#Param("ids") List<Long> managedUserIdList, Pageable page);
SQL Output
Hibernate: select r1_0.review_id, r1_0.caption1, r1_0.caption2, r1_0.caption3, r1_0.date, o2_0.id, o2_0.bodysize_id, o2_0.regDate, o2_0.screenname, o2_0.user_id, r1_0.status, r1_0.url from review as r1_0 inner join ManagedUser as o1_0 on r1_0.owner = o1_0.id left outer join ManagedUser as o2_0 on r1_0.owner = o2_0.id where o2_0.id in (?, ?, ?, ?, ?)
Hibernate: select b1_0.id, b1_0.ankle, b1_0.armLength, b1_0.bust, b1_0.calf, b1_0.chest, b1_0.hairColour, b1_0.hairStyle, b1_0.height, b1_0.hip, b1_0.legLength, b1_0.neck, b1_0.shoulder, b1_0.skinTone, b1_0.thigh, b1_0.upperArm, b1_0.waist, b1_0.weight, b1_0.wrist, m1_0.id, m1_0.regDate, m1_0.screenname, u1_0.user_id, u1_0.country, u1_0.email, u1_0.password, u1_0.points, p1_0.id, p1_0.bodysize_id, p1_0.regDate, p1_0.screenname, p1_0.user_id, u1_0.userLevel from bodysize as b1_0 left outer join ManagedUser as m1_0 on b1_0.id = m1_0.bodysize_id inner join UserAccount as u1_0 on m1_0.user_id = u1_0.user_id left outer join ManagedUser as p1_0 on u1_0.primaryUser_id = p1_0.id where b1_0.id = ?
Hibernate: select b1_0.id, b1_0.ankle, b1_0.armLength, b1_0.bust, b1_0.calf, b1_0.chest, b1_0.hairColour, b1_0.hairStyle, b1_0.height, b1_0.hip, b1_0.legLength, b1_0.neck, b1_0.shoulder, b1_0.skinTone, b1_0.thigh, b1_0.upperArm, b1_0.waist, b1_0.weight, b1_0.wrist, m1_0.id, m1_0.regDate, m1_0.screenname, u1_0.user_id, u1_0.country, u1_0.email, u1_0.password, u1_0.points, p1_0.id, p1_0.bodysize_id, p1_0.regDate, p1_0.screenname, p1_0.user_id, u1_0.userLevel from bodysize as b1_0 left outer join ManagedUser as m1_0 on b1_0.id = m1_0.bodysize_id inner join UserAccount as u1_0 on m1_0.user_id = u1_0.user_id left outer join ManagedUser as p1_0 on u1_0.primaryUser_id = p1_0.id where b1_0.id = ?
Any help solving this would be greatly appreciated

Related

How to combine 2 teradata queries into one

can someone please help me in combining these 2 Teradata queries into a single query? The tables - cdb.dim_party_doc_id, cdb.dim_doc_issuer, mdb.fp_account_entity_map do not have customer_account_number in them, so I not able to directly join all these tables in a single query directly.
Thanks a lot!!
SELECT
det.cust_id AS customer_account_number,
c.encrypt_val AS ssn_encrypted,
det.cust_first_name AS name_1,
bal.BALANCE_AMT AS principal
FROM
cdb.DIM_CUSTOMER det
INNER JOIN
cdb.fact_stored_val_acct_dly bal
ON det.cust_id = bal.customer_id AND bal.curr_cd='USD' and bal.acct_type_code='SBA'
INNER JOIN
cdb.dim_party_acct_map b
ON bal.customer_id = b.cust_id
INNER JOIN
cdb.dim_party_doc_id c
ON b.party_key = c.party_key
AND c.status = 'A'
INNER JOIN
cdb.dim_doc_issuer d
ON c.doc_issuer_id = d.doc_issuer_id
AND d.doc_type = 'TAX_ID'
AND d.doc_subtype = 'SSN'
and
SELECT
own.owner_id AS customer_account_number,
entity.entity_id AS dd_number
FROM
mdb.fp_account_owner_map own
LEFT JOIN
mdb.fp_account_entity_map entity
ON own.fp_account_id = entity.fp_account_id
WHERE
entity.entity_type in (12)
AND
own.product_id in (5501)
Below query solves my problem
SELECT
det.cust_id AS customer_account_number,
temp.direct_deposit_account_number AS account_number,
c.encrypt_val AS ssn_encrypted,
det.cust_first_name AS name_1,
bal.BALANCE_AMT AS principal
FROM
cdb.DIM_CUSTOMER det
LEFT JOIN
cdb.fact_stored_val_acct_dly bal
ON det.cust_id = bal.customer_id AND bal.curr_cd='USD' and bal.acct_type_code='SBA'
INNER JOIN
cdb.dim_party_acct_map b
ON bal.customer_id = b.cust_id
INNER JOIN
cdb.dim_party_doc_id c
ON b.party_key = c.party_key
AND c.status = 'A'
INNER JOIN
cdb.dim_doc_issuer d
ON c.doc_issuer_id = d.doc_issuer_id
AND d.doc_type = 'TAX_ID'
AND d.doc_subtype = 'SSN'
INNER JOIN
(SELECT
own.owner_id AS customer_id,
entity.entity_id AS direct_deposit_account_number
FROM mdb.fp_account_owner_map own
LEFT JOIN
mdb.fp_account_entity_map entity
ON own.fp_account_id = entity.fp_account_id
WHERE entity.entity_type in (12)
AND own.product_id in (5501)) AS temp
ON customer_account_number=temp.customer_id

how can i write sql query with many inner join in eloquent( eager loading) using relationships?

I have this sql query which works fine, how can i write this in eloquent( eager loading) using relationships, not joins.
SELECT ads.id,ads.name,u.name,country_translates.name,city_translate.name,category_translates.name
FROM ads
INNER JOIN users u ON ads.user_id = u.id
INNER JOIN cities ON ads.city_id = cities.id
INNER JOIN country_translates ON cities.country_id = country_translates.country_id
INNER JOIN city_translate ON ads.city_id = city_translate.city_id
INNER JOIN category_translates ON ads.category_id = category_translates.category_id
WHERE country_translates.language_id = 2 AND city_translate.language_id = 2 AND category_translates.language_id = 2

Missing Operator in Query Expression

I have this code
SELECT Sales.InvoiceNo, Sales.SaleDate, Clients.Name, Clients.Address AS
ClientAdrs, Stock.Itemname, Stock.Tax, Stock.Price, Transactions.Qty,
Transactions.NetValue,Transactions.TaxAmount, Transactions.TotalAmount,
Sales.GrossNet, Sales.GrossTax, Sales.GrossTotal, Sales.PrintingCharge,
Sales.LabourCharge, Sales.AdjustableAmount,Sales.GrandTotal, Sales.InWords,
ShopeDetails.Address, ShopeDetails.Email, ShopeDetails.Mobile1,
ShopeDetails.Mobile2, ShopeDetails.TIN, ShopeDetails.AcN,ShopeDetails.IFC
FROM Sales
INNER JOIN Clients
ON Sales.Cid = Clients.Cid
INNER JOIN Transactions
ON Sales.InvoiceNo = Transactions.InvoiceNo
INNER JOIN Stock
ON Transactions.Sid = Stock.Sid
INNER JOIN ShopeDetails
ON Sales.Id = ShopeDetails.Id
and i get this error
Syntax error (missing operator) in query expression
Sales.Cid = Clients.Cid INNER JOIN Transactions ON Sales.InvoiceNo = Transactions.InvoiceNo INNER JOIN Stock ON Transactions.Sid = Stock.Sid INNER JOIN ShopeDetails ON Sales.Id = ShopeDetails.I
Please Help anyone !!
SELECT Sales.InvoiceNo, Sales.SaleDate, Clients.Name, Clients.Address AS
ClientAdrs,Stock.Itemname, Stock.Tax, Stock.Price, Transactions.Qty,
Transactions.NetValue,Transactions.TaxAmount, Transactions.TotalAmount,
Sales.GrossNet, Sales.GrossTax, Sales.GrossTotal, Sales.PrintingCharge,
Sales.LabourCharge, Sales.AdjustableAmount,Sales.GrandTotal, Sales.InWords,
ShopeDetails.Address, ShopeDetails.Email, ShopeDetails.Mobile1,
ShopeDetails.Mobile2, ShopeDetails.TIN, ShopeDetails.AcN,ShopeDetails.IFC
FROM (((Sales INNER JOIN Clients ON Sales.Cid = Clients.Cid)
INNER JOIN Transactions ON Sales.InvoiceNo = Transactions.InvoiceNo)
INNER JOIN Stock ON Transactions.Sid = Stock.Sid )
INNER JOIN ShopeDetails ON Sales.Id = ShopeDetails.Id
this solved the problem

Join the result with new inner query sql

select A.UNIT, A.LEASE_ID, A.MONTHS_GUARANTEED, A.MONTHLY_PAYMENT_AM,
B.DATE_PAID, C.CHARGE_JOB from leasei A
left outer join eq_capture B on A.LEASE_ID = B.LEASE_ID
left outer join eq_mast C on A.UNIT = C.UNIT
where A.DATE_LEASE_EXPIRE = 0
ORDER BY A.LEASE_ID;
I want to use the result of the above query that is use the value C.CHARGE_JOB and the check with another table (job_infojc D) and get the D.STATE value with a where condition C.CHARGE_JOB = D.JOB
Any help is highly appreciated.
Like this:
select D.STATE, X.*
from job_infojc D
join (select A.UNIT, A.LEASE_ID, A.MONTHS_GUARANTEED, A.MONTHLY_PAYMENT_AM,
B.DATE_PAID, C.CHARGE_JOB from leasei A
left outer join eq_capture B on A.LEASE_ID = B.LEASE_ID
left outer join eq_mast C on A.UNIT = C.UNIT
where A.DATE_LEASE_EXPIRE = 0
) X on X.CHARGE_JOB = D.JOB
ORDER BY X.LEASE_ID;

LINQ multiple condition on "on" clause

I have a query which have multiple conditions on on clause
SELECT *
FROM
CATALOGITEM with (nolock) INNER JOIN CATALOG with (nolock) ON
CATALOGITEM.catalog_id = CATALOG.catalog_id and not(catalog.catalog_id = 21) AND NOT(catalog.catalog_id = 20)
INNER JOIN PRODUCT with (nolock) ON
CATALOGITEM.s_num = PRODUCT .s_num
LEFT OUTER JOIN PRODUCT_DETAIL with (nolock) ON
PRODUCT_DETAIL.s_num = PRODUCT.s_num
WHERE
(
CATALOGITEM.publish_code = 'upd' OR
CATALOG_ITEM.publish_code = 'ins' OR
PRODUCT.publish_code = 'upd' OR
PRODUCT.publish_code = 'ins'
)
and
(CATALOG.unit_id = bu.unit_id)
How to write this in LINQ.
Please advice.
Assume you're missing a join to PRODUCT table?
Anyway, this should get you started.
var query = (from ci in db.catalogitem
join c in db.catalog on ci.catalog_id equals c.catalog_id
join p in db.products on ci.s_num equals p.s_num
join pd in db.productdetail on p.s_num equals pd.s_num into tempprods
from prods in tempprods.DefaultIfEmpty()
where !(c.catalog_id.Contains(21, 20))
&& (ci.publish_code.Contains('upd','ins')) ||
(p.publish_code.Contains('upd','ins'))
select ci)
If you want to preserve the (NOLOCK) hints, I have blogged a handy solution using extension methods in C#. Note that this is the same as adding nolock hints to every table in the query.

Resources