JPA相關問題總結

2021-09-13 14:51:34 字數 849 閱讀 6783

1.有nativequery = true和沒有的區別?

有nativequery = true時,是可以執行原生sql語句,所謂原生sql,也就是說這段sql拷貝到資料庫中,然後把引數值給一下就能執行了,比如:

@query(value = "select * from product_rel where audit_id=?1 and process_object=0 ",nativequery = true)

list findallbyproductauditid(integer id);

這個時候,把select * from product_rel where audit_id=?1 and process_object=0拷貝到資料庫中,並給audit_id賦乙個值,那麼這段sql就可以執行。其中資料庫表在資料庫中的表名就是product_rel,欄位audit_id在資料庫中也是真實存在的欄位名。

沒有nativequery = true時,就不是原生sql,而其中的select * from 的***中***也不是資料庫對應的真正的表名,而是對應的實體名,並且sql中的欄位名也不是資料庫中真正的欄位名,而是實體的欄位名。例如:

@query("select ratio from mdmratio mdmratio where enablednum=1 ")

list findbymdmutilthreeprojection();

此中,select ratio from mdmratio中的mdmratio為實體名,不是真正的資料庫表名,真正的資料庫表名是mdm_ratio,而查詢條件中的enablednum在資料庫中真正的名字是enabled_num。

這兩個的作用是一樣的,只是寫法不同而已。涉及到hql的知識。

JPA相關註解

jpa註解 一 基本註解 1 表相關 entity 只要加了這個註解就具備了表和實體的對映關係,表名就是實體名 table name 表名 一般和實體註解一起使用對映表名 2 屬性相關 column name id length 11,nullable false 實體屬性和表字段對映 欄位和屬性相...

JPA註解總結

jpa 註解的幾個要點 1.設定pojo為實體 entity 標識這個pojo是乙個jpa實體 public class users implements serializable 2.設定表名 entity table name users 指定表名為users public class user...

JPA相關註解解釋

tags springdata jpa,title jpa相關註解解釋 target retention runtime public inte ceonetoone 複製 joincolumn註解 target retention runtime public inte cejoincolumn ...