我有一種虛假的問題,我需要做一個@NamedQuery
與其他表,一些簡單的事情加入。JPA @NamedQuery有兩個表,可能嗎?
但在我所有的@NamedQuery
我只處理我的映射對象/表。
舉例來說,在我的對象/表映射汽車:
@NamedQuery(name = Cars.GET_AVAILABLE_CARS,
query = "select c.id from Cars c where c.status = (select d.status from CarStatus d where d.color=red)")
我試圖使用方法:@SecondaryTables
但現在沒有成功。
另外一個工作是將其他表格的所有內容作爲參數給出,但我認爲這在性能上不會很好。
像:
@NamedQuery(name = Cars.GET_AVAILABLE_CARS, query =
"select c.id from Cars c where c.status = :" + CarStatusParam)
任何提示嗎?
在此先感謝
除非您可以使用繼承,@SecondaryTable或映射你的對象映射到第二個表(@OneToOne,...),那麼你將不得不使用@NamedNativeQuery。爲了進一步幫助您,我需要更多地瞭解表結構以及您正在使用的JPA提供程序(例如,EclipseLink具有可以實現此功能的擴展,並允許您使用存儲過程(@NamedStoredProcedureQuery))。 – 2009-12-23 09:00:34
查詢有什麼問題? Cars和CarSatus如何定義和映射? 'd.color = red'無效。 'd.color ='red''可能是正確的。 – 2013-07-26 06:47:15