Skip to content

Commit

Permalink
expand Javadoc of CURRENT_SESSION_CONTEXT_CLASS
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Jul 6, 2022
1 parent 06e44f2 commit 7b0270c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Expand Up @@ -1015,7 +1015,13 @@ public interface AvailableSettings {
/**
* Specifies a {@link org.hibernate.context.spi.CurrentSessionContext} for
* scoping the {@linkplain org.hibernate.SessionFactory#getCurrentSession()
* current session}.
* current session}, either:<ul>
* <li>{@code jta}, {@code thread}, or {@code managed}, or
* <li>the name of a class implementing
* {@code org.hibernate.context.spi.CurrentSessionContext}.
* </ul>
*
* @see org.hibernate.SessionFactory#getCurrentSession()
*/
String CURRENT_SESSION_CONTEXT_CLASS = "hibernate.current_session_context_class";

Expand Down
Expand Up @@ -7,16 +7,21 @@
package org.hibernate.orm.test.stateless;

import java.util.Date;
import java.util.List;

import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;

import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.Transaction;

import org.hibernate.cfg.Environment;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

Expand All @@ -31,6 +36,9 @@
xmlMappings = "org/hibernate/orm/test/stateless/Document.hbm.xml"
)
@SessionFactory
@ServiceRegistry(
settings = @Setting(name = Environment.STATEMENT_BATCH_SIZE, value = "4")
)
public class StatelessSessionTest {

@AfterEach
Expand All @@ -41,6 +49,42 @@ public void tearDown(SessionFactoryScope scope){
);
}


@Test
public void testCreateBatch(SessionFactoryScope scope) {
scope.inStatelessSession(
statelessSession -> {
try {
Transaction tx = statelessSession.beginTransaction();
Document doc1 = new Document( "blah", "Blahs1" );
statelessSession.insert( doc1 );
assertNotNull( doc1.getName() );

System.out.println("blah");
Document doc2 = new Document( "blah blah", "Blahs2" );
statelessSession.insert( doc2 );
assertNotNull( doc2.getName() );
System.out.println("blah blah");

Document doc3 = new Document( "blah blah blah", "Blahs3" );
statelessSession.insert( doc3 );
assertNotNull( doc3.getName() );
System.out.println("blah blah blah");
Date initVersion = doc1.getLastModified();
assertNotNull( initVersion );
tx.commit();

List documents = statelessSession.createQuery("from Document").getResultList();
assertEquals( 3, documents.size() );
}
catch (Exception e) {
if ( statelessSession.getTransaction().isActive() ) {
statelessSession.getTransaction().rollback();
}
throw e;
}
} );
}
@Test
public void testCreateUpdateReadDelete(SessionFactoryScope scope) {
scope.inStatelessSession(
Expand Down

0 comments on commit 7b0270c

Please sign in to comment.