永続レイヤのデータベース・ロック制御


詳細
Webサイトは最近、同時アクセスが増加しており、logは次の異常を投げ出すことが多い.
Caused by: java.sql.BatchUpdateException: Lock wait timeout exceeded; try restarting transaction
 
org.springframework.dao.CannotAcquireLockException: Hibernate flushing: Could not execute JDBC batch update; SQL [update fb_session_keys set hh_session_key=?, last_update=?, live_forever=?, session_key=?, uid=? where id=?]; Lock wait timeout exceeded; try restarting transaction; nested exception is java.sql.BatchUpdateException: Lock wait timeout exceeded; try restarting transaction
 
fb_session_keysこの時計は高合併時にロックされて、幽霊に会いました!
 
entityを調べるとデータベースロックが設定されていないことがわかり、ormはjpa annotationを使用しています
 
楽観的なロックを使って解決しなければなりません.
 
        private Integer version=Integer.valueOf(0); //       
	
	@Version
	public Integer getVersion() {
		return version;
	}
	public void setVersion(Integer version) {
		this.version = version;
	}

仕事が终わる!