2016-07-30 46 views
0

我使用Spring MVC和NamedParameterJdbcOperationsREST - 在不休眠的情況下獲取新創建的資源

我正在做一個休息調用來創建一個對象,我想返回這個新創建的對象。

那麼不管使用哪個數據庫,我如何才能返回新創建的對象?

我沒有使用hibernate。在休眠狀態下,持久化對象可以立即返回。但是我想在沒有休眠的情況下實現這一點。

回答

0

我用NamedParameterJdbcOperations的更新方法獲取新創建的對象的關鍵,然後使用此關鍵碼獲取對象。

拿到鑰匙 -

GeneratedKeyHolder holder = new GeneratedKeyHolder(); 

namedParameterJdbcOperations.update(sql,sqlParameterSource,holder); 
int key = holder.getKey().intValue(); 
相關問題