Skip to content

Commit eb02115

Browse files
Sannegsmet
authored andcommitted
HSEARCH-2302 Avoid depending on implementation details to get the JPA FlushMode for a Query
1 parent d29f560 commit eb02115

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

orm/src/main/java/org/hibernate/search/jpa/impl/FullTextEntityManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ else if ( Session.class.isAssignableFrom( delegate.getClass() ) ) {
9494
@Override
9595
public FullTextQuery createFullTextQuery(org.apache.lucene.search.Query luceneQuery, Class<?>... entities) {
9696
FullTextSession ftSession = getFullTextSession();
97-
return new FullTextQueryImpl( ftSession.createFullTextQuery( luceneQuery, entities ), ftSession );
97+
return new FullTextQueryImpl( ftSession.createFullTextQuery( luceneQuery, entities ), ftSession, em );
9898
}
9999

100100
@Override
101101
public FullTextQuery createFullTextQuery(QueryDescriptor descriptor, Class<?>... entities) {
102102
FullTextSession ftSession = getFullTextSession();
103-
return new FullTextQueryImpl( ftSession.createFullTextQuery( descriptor, entities ), ftSession );
103+
return new FullTextQueryImpl( ftSession.createFullTextQuery( descriptor, entities ), ftSession, em );
104104
}
105105

106106
@Override

orm/src/main/java/org/hibernate/search/jpa/impl/FullTextQueryImpl.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.Set;
1818
import java.util.concurrent.TimeUnit;
1919
import javax.persistence.EntityExistsException;
20+
import javax.persistence.EntityManager;
2021
import javax.persistence.EntityNotFoundException;
2122
import javax.persistence.FlushModeType;
2223
import javax.persistence.LockModeType;
@@ -69,15 +70,18 @@ final class FullTextQueryImpl implements FullTextQuery {
6970

7071
private final org.hibernate.search.FullTextQuery query;
7172
private final Session session;
73+
private final EntityManager em;
74+
7275
private Integer firstResult;
7376
private Integer maxResults;
7477
//initialized at 0 since we don't expect to use hints at this stage
7578
private final Map<String, Object> hints = new HashMap<String, Object>( 0 );
7679
private FlushModeType jpaFlushMode;
7780

78-
public FullTextQueryImpl(org.hibernate.search.FullTextQuery query, Session session) {
81+
public FullTextQueryImpl(org.hibernate.search.FullTextQuery query, Session session, EntityManager em) {
7982
this.query = query;
8083
this.session = session;
84+
this.em = em;
8185
}
8286

8387
@Override
@@ -512,16 +516,7 @@ public FlushModeType getFlushMode() {
512516
if ( jpaFlushMode != null ) {
513517
return jpaFlushMode;
514518
}
515-
final FlushMode hibernateFlushMode = session.getFlushMode();
516-
if ( FlushMode.AUTO == hibernateFlushMode ) {
517-
return FlushModeType.AUTO;
518-
}
519-
else if ( FlushMode.COMMIT == hibernateFlushMode ) {
520-
return FlushModeType.COMMIT;
521-
}
522-
else {
523-
return null; //incompatible flush mode
524-
}
519+
return em.getFlushMode();
525520
}
526521

527522
@Override

0 commit comments

Comments
 (0)