Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import java.io.Serializable;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

import jakarta.persistence.EntityGraph;
import org.hibernate.graph.RootGraph;
Expand All @@ -15,6 +17,8 @@
import org.hibernate.query.QueryProducer;
import org.hibernate.query.criteria.HibernateCriteriaBuilder;

import static org.hibernate.internal.TransactionManagement.manageTransaction;

/**
* Declares operations that are common between {@link Session} and {@link StatelessSession}.
*
Expand Down Expand Up @@ -432,4 +436,31 @@ public interface SharedSessionContract extends QueryProducer, AutoCloseable, Ser
* The factory which created this session.
*/
SessionFactory getFactory();

/**
* Perform an action within the bounds of a {@linkplain Transaction
* transaction} associated with this session.
*
* @param action a void function which accepts the {@link Transaction}
*
* @since 7.0
*/
default void inTransaction(Consumer<? super Transaction> action) {
final Transaction transaction = beginTransaction();
manageTransaction( transaction, transaction, action );
}

/**
* Obtain a value within the bounds of a {@linkplain Transaction
* transaction} associated with this session.
*
* @param action a function which accepts the {@link Transaction} and
* returns the value
*
* @since 7.0
*/
default <R> R fromTransaction(Function<? super Transaction,R> action) {
final Transaction transaction = beginTransaction();
return manageTransaction( transaction, transaction, action );
}
}
Loading