解決JPA查詢資料後修改,資料庫會更新

2021-09-26 08:19:01 字數 416 閱讀 4032

查詢資料後對entity進行修改,資料庫對應欄位會自動更新。

解決方法如下:

1. 使用beanutils

new乙個新實體,將查詢出來的實體複製給新實體,修改之後返回新實體物件。

beanutils.copyproperties(entity,newentity);

newentity.set...

2. 使用@transactional註解

在dao層對應方法使用該註解,表示以非事務方式執行操作,如果當前存在事務,就把當前事務掛起(只查詢)。

@transactional(propagation=propagation.not_supported)

修改資料庫

改資料庫庫名稱 alter database 資料庫名稱 modify name 新資料庫名稱 或exec sp renamedb 資料庫名稱 新資料庫名稱 擴大資料庫 alter database語句擴大資料庫 alter database studentsys add file name stu...

C 資料庫SQLServer查詢 修改資料

今天又得寫乙個資料庫sql server讀寫的小工具,主要是涉及到一些簡單的操作,沒什麼技術含量。public static sqlconnection conn static void main string args 資料庫連線 private static void connectiondb ...

EF codefirst後修改資料庫結構的處理

1.開啟工具 nuget包管理器 程式包管理器控制台 enable migrations 2.在pm 後面輸入enable migrations contexttypename databasename 如果執行失敗,就參考失敗信資訊重新輸入,失敗資訊提示的非常明確 databasename是你生成...