1
在我的項目中,我必須實現多租戶功能(針對每個客戶)。 這個想法是在每個實體中存儲一個屬性(customer_id)用於分隔。Spring-JPA:一般地擴展JPA查詢
要獲取某個客戶的數據,我需要使用此屬性擴展SQL。
實施例:
billRepository.findByDateAndCustomerId(date, customerId);
結果是
select * from bill where date = ? and customer_id = ?
但我希望有一種方法等
billRepository.findByDate(date);
,結果將是象上面相同。
select * from bill where date = ? and customer_id = ?
是否有可能以通用的方式注入customer_id(例如sql預處理器)? 任何想法如何用spring-jpa或JPA(休眠)做到這一點?
由於 chokdee
儘管海報要求提供JPA,但這不是JPA,那麼也許應該使用JPA Criteria重寫您的內容? –
對不起,也許這是誤解。但我的意思是不要直接使用SQL。使用JPA以隱藏方式注入customer_id。 – chokdee