1,使用JDBC方式
Session session = entityManager.unwrap( Session.
class
);
Integer commentCount = session.doReturningWork(
connection -> {
try
(CallableStatement function = connection
.prepareCall(
"{ ? = call fn_count_comments(?) }"
)) {
function.registerOutParameter(
1
, Types.INTEGER );
function.setInt(
2
,
1
);
function.execute();
return
function.getInt(
1
);
}
} );
注调用方法必须加上@
Transactional 否则错
java.lang.IllegalStateException:no transactional EntityManager available