searchFactory = session.getSearchFactory();
// create some different domains:
{
session.beginTransaction();
session.persist( new Domain( 1, "jboss.org" ) );
session.persist( new Domain( 2, "jboss.com" ) );
session.persist( new Domain( 3, "hibernate.org" ) );
session.persist( new Domain( 4, "geocities.com" ) );
session.getTransaction().commit();
}
assertEquals( 2, countDomainsByFullText( "jboss" ) );
assertEquals( 1, countDomainsByFullText( "hibernate" ) );
assertEquals( 1, countDomainsByFullText( "geocities" ) );
// now create some and delete others:
{
session.beginTransaction();
session.persist( new Domain( 5, "sun.com" ) );
session.persist( new Domain( 6, "mysql.com" ) );
session.persist( new Domain( 7, "oracle.com" ) );
Domain hibernateDomain = (Domain) session.get( Domain.class, 3 );
session.delete( hibernateDomain );
Domain geocitiesDomain = (Domain) session.get( Domain.class, 4 );
session.delete( geocitiesDomain );
session.getTransaction().commit();
}
assertEquals( 0, countDomainsByFullText( "hibernate" ) );
assertEquals( 0, countDomainsByFullText( "geocities" ) );
assertEquals( 2, countDomainsByFullText( "jboss" ) );
assertEquals( 1, countDomainsByFullText( "sun" ) );
assertEquals( 1, countDomainsByFullText( "mysql" ) );
assertEquals( 1, countDomainsByFullText( "oracle" ) );
// use create/update/delete:
{
session.beginTransaction();
session.persist( new Domain( 3, "hibernate.org" ) );
Domain mysqlDomain = (Domain) session.get( Domain.class, 6 );
session.delete( mysqlDomain );
//persisting a new entity having the same PK as a deleted one:
session.persist( new Domain( 6, "myhql.org" ) );
Domain sunDomain = (Domain) session.get( Domain.class, 5 );
sunDomain.setName( "community.oracle.com" );
session.getTransaction().commit();
}
assertEquals( 1, countDomainsByFullText( "hibernate" ) );
assertEquals( 2, countDomainsByFullText( "oracle" ) );
assertEquals( 1, countDomainsByFullText( "myhql" ) );
assertEquals( 1, countDomainsByFullText( "community" ) );
assertEquals( 0, countDomainsByFullText( "mysql" ) );
// now creating and deleting the "same" (as by pk) entity several times in same transaction:
{
session.beginTransaction();
session.persist( new Domain( 8, "mysql.org" ) );
Domain mysqlDomain = (Domain) session.load( Domain.class, 8 );
session.delete( mysqlDomain );
Domain newDomain = new Domain( 8, "something.org" );
session.persist( newDomain );
session.delete( newDomain );
session.persist( new Domain( 8, "somethingnew.org" ) );
session.getTransaction().commit();
}
assertEquals( 1, countDomainsByFullText( "somethingnew" ) );
session.close();