Felix König (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5a4bad5...
) *commented* on HHH-4042 (
https://hibernate.atlassian.net/browse/HHH-4042?atlOrigin=eyJpIjoiOTY1MTI...
)
Re: StatelessSession does not flush when using jdbc batch_size > 1 (
https://hibernate.atlassian.net/browse/HHH-4042?atlOrigin=eyJpIjoiOTY1MTI...
)
This is still a problem and source of potential data loss in hibernate 6.1.7. For my case,
which is Spring Boot, I’ve implemented this workaround:
@Service
public class StatelessSessionRunner {
private final Session session;
public StatelessSessionRunner(Session session) {
this.session = session;
}
public <T> T runWithStatelessSession(Function<StatelessSession, T> func) {
return session.doReturningWork(connection -> {
try (StatelessSession statelessSession =
session.getSessionFactory().openStatelessSession(connection)) {
var result = func.apply(statelessSession);
// workaround for
https://hibernate.atlassian.net/browse/HHH-4042
((SharedSessionContractImplementor)
statelessSession).getJdbcCoordinator().executeBatch();
return result;
}
});
}
}
Which allows you to perform some operations using a stateless session within a larger
transaction.
(
https://hibernate.atlassian.net/browse/HHH-4042#add-comment?atlOrigin=eyJ...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-4042#add-comment?atlOrigin=eyJ...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100217- sha1:65be9f2 )