I know, that there is a way to descend to a low level - get connection and perform two transaction's by hand in a single hibernate session.
But the question is - how to invoke second nested transaction in the same Session via @Transactional annotations (not using "low level hacks" or handwrited custom transaction management)?
Some possible code:
@Service
public class DoubleTransaction {
@Autowired
private SessionFactory sf;
@Autowired
private NestedTeHandler nestedHandler;
@Transactional
void invokeTransaction() {
Session cs = sf.getCurrentSession();
Session nestedCs = nestedHandler.invokeNested(sf);
System.out.println(cs == nestedCs);
}}
@Service
public class NestedTeHandler {
@Transactional
Session invokeNested(SessionFactory sf) {
return sf.getCurrentSession();
}}