Skip to content

Commit

Permalink
#119 unwrap session from emf directly
Browse files Browse the repository at this point in the history
  • Loading branch information
mincong-h committed Aug 7, 2016
1 parent 251ff72 commit 88e89f4
Showing 1 changed file with 4 additions and 5 deletions.
Expand Up @@ -13,11 +13,11 @@
import javax.batch.runtime.context.JobContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.search.backend.spi.BatchBackend;
import org.hibernate.search.hcore.util.impl.ContextHelper;
import org.hibernate.search.jsr352.internal.JobContextData;
Expand All @@ -37,7 +37,7 @@ public class AfterChunkBatchlet implements Batchlet {

@PersistenceUnit(unitName = "h2")
private EntityManagerFactory emf;
private EntityManager em;
private Session session;

@Inject
@BatchProperty
Expand All @@ -54,8 +54,7 @@ public String process() throws Exception {
if ( this.optimizeAtEnd ) {

logger.info( "purging index for all entities ..." );
em = emf.createEntityManager();
Session session = em.unwrap( Session.class );
session = emf.unwrap( SessionFactory.class ).openSession();
final BatchBackend backend = ContextHelper
.getSearchintegrator( session )
.makeBatchBackend( null );
Expand All @@ -72,7 +71,7 @@ public String process() throws Exception {
@Override
public void stop() throws Exception {
try {
em.close();
session.close();
}
catch ( Exception e ) {
logger.error( e );
Expand Down

0 comments on commit 88e89f4

Please sign in to comment.