최대 절전 모드 세션 'doWork()
메서드를 사용하면 java.sql.Connection
에 직접 액세스 할 수 있습니다.시퀀스 ID 생성을 위해 최대 절전 모드 Session.doWork 사용
다음은이 작업을 수행 할 수있는 더 좋은 방법이있다, 만들고 PreparedStatement
순서를
public Long generateId() {
final Long id[] = { null };
getSessionFactory().openSession().doWork(new Work() {
public void execute(Connection connection) throws SQLException {
PreparedStatement ps = connection
.prepareStatement("SELECT HIB_SEQ.nextval FROM DUAL");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
id[0] = rs.getLong(0);
}
}
});
return id[0];
}
첫째을 생성하기 위해 실행할 수있는 방법 중 하나입니다?
두 번째 질문 위에서 작성한 PreparedStatement
을 명시 적으로 닫아야합니까?