Tabnine Logo
SessionImplementor.persist
Code IndexAdd Tabnine to your IDE (free)

How to use
persist
method
in
org.hibernate.engine.spi.SessionImplementor

Best Java code snippets using org.hibernate.engine.spi.SessionImplementor.persist (Showing top 20 results out of 315)

origin: hibernate/hibernate-orm

@Override
public void persist(String entityName, Object object, Map createdAlready) throws HibernateException {
  delegate.persist( entityName, object, createdAlready );
}
origin: hibernate/hibernate-orm

@Override
public void persist(Object object) {
  delegate.persist( object );
}
origin: hibernate/hibernate-orm

@Override
public void persist(String entityName, Object object) {
  delegate.persist( entityName, object );
}
origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-12150" )
public void testReferenceToAlreadyMappedColumn() {
  inTransaction(
      session -> {
        AddressCapable2 holder = new AddressCapable2( 1, "osd");
        Address2 address = new Address2( 1, "123 Main St" );
        session.persist( holder );
        session.persist( address );
      }
  );
  inTransaction(
      session -> {
        AddressCapable2 holder = session.get( AddressCapable2.class, 1 );
        Address2 address = session.get( Address2.class, 1 );
        holder.addresses.put( "work", address );
        session.persist( holder );
      }
  );
  inTransaction(
      session -> {
        AddressCapable2 holder = session.get( AddressCapable2.class, 1 );
        assertEquals( 1, holder.addresses.size() );
        final Map.Entry<String,Address2> entry = holder.addresses.entrySet().iterator().next();
        assertEquals( "work", entry.getKey() );
        assertEquals( null, entry.getValue().type );
        session.remove( holder );
      }
  );
}
origin: hibernate/hibernate-orm

Address2 address = new Address2( 1, "123 Main St" );
session.persist( holder );
session.persist( address );
holder.addresses.put( "work", address );
session.persist( holder );
origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-12150" )
public void testReferenceToNonMappedColumn() {
  inTransaction(
      session -> {
        AddressCapable holder = new AddressCapable( 1, "osd");
        Address address = new Address( 1, "123 Main St" );
        session.persist( holder );
        session.persist( address );
      }
  );
  inTransaction(
      session -> {
        AddressCapable holder = session.get( AddressCapable.class, 1 );
        Address address = session.get( Address.class, 1 );
        holder.addresses.put( "work", address );
        session.persist( holder );
      }
  );
  inTransaction(
      session -> {
        AddressCapable holder = session.get( AddressCapable.class, 1 );
        assertEquals( 1, holder.addresses.size() );
        final Map.Entry<String,Address> entry = holder.addresses.entrySet().iterator().next();
        assertEquals( "work", entry.getKey() );
        session.remove( holder );
      }
  );
}
origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-12150" )
public void testReferenceToNonMappedColumn() {
  inTransaction(
      session -> {
        AddressCapable holder = new AddressCapable( 1, "osd");
        Address address = new Address( 1, "123 Main St" );
        session.persist( holder );
        session.persist( address );
      }
  );
  inTransaction(
      session -> {
        AddressCapable holder = session.get( AddressCapable.class, 1 );
        Address address = session.get( Address.class, 1 );
        holder.addresses.put( "work", address );
        session.persist( holder );
      }
  );
  inTransaction(
      session -> {
        AddressCapable holder = session.get( AddressCapable.class, 1 );
        assertEquals( 1, holder.addresses.size() );
        final Map.Entry<String,Address> entry = holder.addresses.entrySet().iterator().next();
        assertEquals( "work", entry.getKey() );
        session.remove( holder );
      }
  );
}
origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-12150" )
public void testReferenceToAlreadyMappedColumn() {
  inTransaction(
      session -> {
        AddressCapable2 holder = new AddressCapable2( 1, "osd");
        session.persist( holder );
      }
  );
  inTransaction(
      session -> {
        AddressCapable2 holder = session.get( AddressCapable2.class, 1 );
        Address2 address = new Address2( 1, "123 Main St" );
        address.type = "work";
        holder.addresses.put( "work", address );
        session.persist( holder );
      }
  );
  inTransaction(
      session -> {
        AddressCapable2 holder = session.get( AddressCapable2.class, 1 );
        assertEquals( 1, holder.addresses.size() );
        final Map.Entry<String,Address2> entry = holder.addresses.entrySet().iterator().next();
        assertEquals( "work", entry.getKey() );
        assertEquals( "work", entry.getValue().type );
        session.remove( holder );
      }
  );
}
origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-12150" )
public void testReferenceToNonMappedColumn() {
  inTransaction(
      session -> {
        AddressCapable holder = new AddressCapable( 1, "osd");
        session.persist( holder );
      }
  );
  inTransaction(
      session -> {
        AddressCapable holder = session.get( AddressCapable.class, 1 );
        holder.addresses.put( "work", new Address( 1, "123 Main St" ) );
        session.persist( holder );
      }
  );
  inTransaction(
      session -> {
        AddressCapable holder = session.get( AddressCapable.class, 1 );
        assertEquals( 1, holder.addresses.size() );
        final Map.Entry<String,Address> entry = holder.addresses.entrySet().iterator().next();
        assertEquals( "work", entry.getKey() );
        session.remove( holder );
      }
  );
}
origin: hibernate/hibernate-orm

@Before
public void createTestData() {
  inTransaction(
      s -> {
        parent = new Parent( 99999L );
        s.persist( parent );
        Child c = new Child( parent );
        parent.getChildren().add( c );
        c.setParent( parent );
      }
  );
}
origin: hibernate/hibernate-orm

@Before
public void createTestData() {
  inTransaction(
      s -> {
        parent = new Parent( 99999L );
        s.persist( parent );
        Child c = new Child( parent );
        parent.getChildren().add( c );
        c.setParent( parent );
      }
  );
}
origin: hibernate/hibernate-orm

@Before
public void createData() {
  inTransaction(
      session -> {
        final Customer cust = new Customer( 1, "Acme Corp");
        final Order order1 = new Order( 1, cust, "123" );
        final Order order2 = new Order( 2, cust, "456" );
        session.persist( cust );
      }
  );
}
origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-3930" )
public void testEagerFetchBidirectionalOneToOneWithDirectFetching() {
  inTransaction( session -> {
    EntityA a = new EntityA( 1L, new EntityB( 2L ) );
    
    session.persist( a );
    session.flush();
    session.clear();
    // Use atomic integer because we need something mutable
    final AtomicInteger queryExecutionCount = new AtomicInteger();
    
    session.getEventListenerManager().addListener( new StatisticalLoggingSessionEventListener() {
      @Override
      public void jdbcExecuteStatementStart() {
        super.jdbcExecuteStatementStart();
        queryExecutionCount.getAndIncrement();
      }
    } );
    
    session.find( EntityA.class, 1L );
    
    assertEquals(
        "Join fetching inverse one-to-one didn't use the object already present in the result set!",
        1,
        queryExecutionCount.get()
    );
  } );
}
origin: hibernate/hibernate-orm

@Test
public void testOnlySubclassIsCached() {
  final StatisticsImplementor statistics = sessionFactory().getStatistics();
  inTransaction(
      s -> s.persist( new Customer( 1, "Acme Corp", "123" ) )
  );
  assertTrue( sessionFactory().getCache().contains( Customer.class, 1 ) );
  inTransaction(
      s -> {
        statistics.clear();
        final Customer customer = s.get( Customer.class, 1 );
        assertTrue( Hibernate.isInitialized( customer ) );
        assertThat( statistics.getSecondLevelCacheHitCount(), CoreMatchers.is(1L) );
      }
  );
}
origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-3930" )
public void testFetchBidirectionalOneToOneWithOneJoinFetch() {
  inTransaction( session -> {
    EntityA a = new EntityA( 1L, new EntityB( 2L ) );
    session.persist( a );
    session.flush();
    session.clear();
    // Use atomic integer because we need something mutable
    final AtomicInteger queryExecutionCount = new AtomicInteger();
    session.getEventListenerManager().addListener( new StatisticalLoggingSessionEventListener() {
      @Override
      public void jdbcExecuteStatementStart() {
        super.jdbcExecuteStatementStart();
        queryExecutionCount.getAndIncrement();
      }
    } );
    session.createQuery(
        "from EntityA a join fetch a.b"
    ).list();
    assertEquals(
        "Join fetching inverse one-to-one didn't use the object already present in the result set!",
        1,
        queryExecutionCount.get()
    );
  } );
}
origin: hibernate/hibernate-orm

@Test
@TestForIssue( jiraKey = "HHH-3930" )
public void testFetchBidirectionalOneToOneWithCircularJoinFetch() {
  inTransaction( session -> {
    EntityA a = new EntityA( 1L, new EntityB( 2L ) );
    session.persist( a );
    session.flush();
    session.clear();
    // Use atomic integer because we need something mutable
    final AtomicInteger queryExecutionCount = new AtomicInteger();
    session.getEventListenerManager().addListener( new StatisticalLoggingSessionEventListener() {
      @Override
      public void jdbcExecuteStatementStart() {
        super.jdbcExecuteStatementStart();
        queryExecutionCount.getAndIncrement();
      }
    } );
    session.createQuery(
        "from EntityA a join fetch a.b b join fetch b.a"
    ).list();
    assertEquals(
        "Join fetching inverse one-to-one didn't use the object already present in the result set!",
        1,
        queryExecutionCount.get()
    );
  } );
}
origin: hibernate/hibernate-orm

@Test
public void testUnstrictUnversioned() {
  sessionFactory = buildSessionFactory( Person.class, false );
  final StatisticsImplementor statistics = sessionFactory.getStatistics();
  inTransaction(
      sessionFactory,
      s -> s.persist( new Person( "1", "John Doe", true ) )
  );
  // it should not be in the cache because it should be invalidated instead
  assertEquals( statistics.getSecondLevelCachePutCount(), 0 );
  assertFalse( sessionFactory.getCache().contains( Person.class, "1" ) );
  inTransaction(
      sessionFactory,
      s -> {
        statistics.clear();
        final Person person = s.get( Person.class, "1" );
        assertTrue( Hibernate.isInitialized( person ) );
        assertThat( statistics.getSecondLevelCacheHitCount(), CoreMatchers.is( 0L) );
        statistics.clear();
      }
  );
}
origin: hibernate/hibernate-orm

@Test
public void testVersioned() {
  sessionFactory = buildSessionFactory( VersionedPerson.class, false );
  final StatisticsImplementor statistics = sessionFactory.getStatistics();
  inTransaction(
      sessionFactory,
      s -> s.persist( new VersionedPerson( "1", "John Doe", true ) )
  );
  // versioned data should be cacheable regardless
  assertEquals( statistics.getSecondLevelCachePutCount(), 1 );
  assertTrue( sessionFactory.getCache().contains( VersionedPerson.class, "1" ) );
  inTransaction(
      sessionFactory,
      s -> {
        statistics.clear();
        final VersionedPerson person = s.get( VersionedPerson.class, "1" );
        assertTrue( Hibernate.isInitialized( person ) );
        assertThat( statistics.getSecondLevelCacheHitCount(), CoreMatchers.is( 1L ) );
        statistics.clear();
      }
  );
}
origin: hibernate/hibernate-orm

@Test
public void testStrictUnversioned() {
  sessionFactory = buildSessionFactory( Person.class, true );
  final StatisticsImplementor statistics = sessionFactory.getStatistics();
  inTransaction(
      sessionFactory,
      s -> s.persist( new Person( "1", "John Doe", true ) )
  );
  // this time it should be iun the cache because we enabled JPA compliance
  assertEquals( statistics.getSecondLevelCachePutCount(), 1 );
  assertTrue( sessionFactory.getCache().contains( Person.class, "1" ) );
  inTransaction(
      sessionFactory,
      s -> {
        statistics.clear();
        final Person person = s.get( Person.class, "1" );
        assertTrue( Hibernate.isInitialized( person ) );
        assertThat( statistics.getSecondLevelCacheHitCount(), CoreMatchers.is( 1L) );
        statistics.clear();
      }
  );
}
origin: hibernate/hibernate-orm

@Test
public void testOnlySubclassIsCached() {
  final StatisticsImplementor statistics = sessionFactory().getStatistics();
  inTransaction(
      s -> {
        s.persist( new Employee( "1", "John Doe", "987", "engineering") );
        s.persist( new Customer( "2", "Acme Corp", "123" ) );
      }
  );
  assertTrue( sessionFactory().getCache().contains( Employee.class, "1" ) );
  assertTrue( sessionFactory().getCache().contains( Person.class, "1" ) );
  assertFalse( sessionFactory().getCache().contains( Customer.class, "2" ) );
  assertFalse( sessionFactory().getCache().contains( Person.class, "2" ) );
  inTransaction(
      s -> {
        statistics.clear();
        final Customer customer = s.get( Customer.class, "2" );
        assertTrue( Hibernate.isInitialized( customer ) );
        assertThat( statistics.getSecondLevelCacheHitCount(), CoreMatchers.is(0L) );
        statistics.clear();
        final Employee emp = s.get( Employee.class, "1" );
        assertTrue( Hibernate.isInitialized( emp ) );
        assertThat( statistics.getSecondLevelCacheHitCount(), CoreMatchers.is(1L) );
      }
  );
}
org.hibernate.engine.spiSessionImplementorpersist

Popular methods of SessionImplementor

  • getFactory
    Get the creating SessionFactoryImplementor
  • getTransactionCoordinator
  • connection
  • getPersistenceContext
    Get the persistence context for this session
  • getLoadQueryInfluencers
    Get the load query influencers associated with this session.
  • isTransactionInProgress
    Does this Session have an active Hibernate transaction or is there a JTA transaction in progress?
  • getEntityPersister
    Get the EntityPersister for any instance
  • getJdbcCoordinator
  • isClosed
    Determine whether the session is closed. Provided separately from #isOpen() as this method does not
  • flush
  • getTenantIdentifier
    Match te method on org.hibernate.Session and org.hibernate.StatelessSession
  • generateEntityKey
  • getTenantIdentifier,
  • generateEntityKey,
  • getContextEntityIdentifier,
  • isOpen,
  • bestGuessEntityName,
  • getFlushMode,
  • getSessionFactory,
  • guessEntityName,
  • immediateLoad,
  • initializeCollection

Popular in Java

  • Parsing JSON documents to java classes using gson
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getResourceAsStream (ClassLoader)
  • putExtra (Intent)
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now