Hi guys,
I'm using hibernate search 3.0.1.GA (shipped with seam 2.1.1.GA).
I'm having a situation trying to index my database for the first time.
The Class I'm trying to index has many associations. It works if I include only one association but when I try in index 2+ associations together with my class, I have this issue :
Code:
Caused by: javax.ejb.EJBException: org.hibernate.HibernateException: cannot simultaneously fetch multiple bags
at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:63)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:83)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:206)
at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:119)
at $Proxy201.index(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
at org.jboss.seam.ejb.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:43)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
at org.javassist.tmp.java.lang.Object_$$_javassist_0.index(Object_$$_javassist_0.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
at org.jboss.seam.Component.callComponentMethod(Component.java:2210)
at org.jboss.seam.Component.callCreateMethod(Component.java:2133)
at org.jboss.seam.Component.newInstance(Component.java:2093)
... 141 more
Caused by: org.hibernate.HibernateException: cannot simultaneously fetch multiple bags
at org.hibernate.loader.BasicLoader.postInstantiate(BasicLoader.java:66)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:81)
at org.hibernate.impl.SessionImpl.scroll(SessionImpl.java:1523)
at org.hibernate.impl.CriteriaImpl.scroll(CriteriaImpl.java:297)
at com.easycity.ejb.util.IndexerBean.indexPOI(IndexerBean.java:192)
at com.easycity.ejb.util.IndexerBean.index(IndexerBean.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:31)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:71)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
... 179 more
Here is my code :
Code:
@SuppressWarnings("unchecked")
private void indexPOI() {
FullTextSession fullTextSession = getFullTextSession();
/*
fullTextSession.setFlushMode(org.hibernate.FlushMode.MANUAL);
fullTextSession.setCacheMode(CacheMode.IGNORE);
*/
org.hibernate.Transaction transaction = fullTextSession
.beginTransaction();
// Scrollable results will avoid loading too many objects in memory
org.hibernate.Criteria query = fullTextSession
.createCriteria(POI.class)
.setFetchMode("detailsSet", org.hibernate.FetchMode.JOIN)
.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
.setCacheMode(CacheMode.IGNORE)
.setFetchSize(FETCH_SIZE)
.setFlushMode(org.hibernate.FlushMode.MANUAL);
query.setFetchMode("reviewSet", org.hibernate.FetchMode.JOIN)
.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
.setCacheMode(CacheMode.IGNORE)
.setFetchSize(FETCH_SIZE)
.setFlushMode(org.hibernate.FlushMode.MANUAL);
/*
query.setFetchMode("mainCategory", org.hibernate.FetchMode.JOIN)
.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
.setCacheMode(CacheMode.IGNORE)
.setFetchSize(FETCH_SIZE)
.setFlushMode(org.hibernate.FlushMode.MANUAL);
*/
/*
query.setFetchMode("mainCategory.detailsSet", org.hibernate.FetchMode.JOIN)
.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
.setCacheMode(CacheMode.IGNORE)
.setFetchSize(FETCH_SIZE)
.setFlushMode(org.hibernate.FlushMode.MANUAL);
*/
org.hibernate.ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY);
int index = 0;
while (results.next()) {
index++;
fullTextSession.index(results.get(0)); // index each element
if (index % BATCH_SIZE == 0) {
System.out.println("...indexing POI : " + index);
fullTextSession.clear(); // clear every batchSize since the
// queue is processed
}
}
transaction.commit();
try {
if (results != null) {
results.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
My entities :
POIDetails -- * -------- 1 -- POI --1---------*-- Review
Code:
@Entity
@Indexed
@FullTextFilterDefs( {
@FullTextFilterDef(name = "activePOI", impl = ActivePOIFilter.class, cache=false)
})
@Table(name = "POI")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "POI_TYPE", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("POI")
@SequenceGenerator(name = "POI_SEQUENCE", sequenceName = "POI_POI_ID_SEQ")
public class POI implements java.io.Serializable, Cloneable {
// Attributes
@DocumentId
private Long id;
[...]
@Field(index=Index.TOKENIZED, store=Store.NO)
private String nameBase;
// Associations
@CollectionOfElements
@IndexedEmbedded(depth = 1)
private Collection<POIDetails> detailsSet = new ArrayList<POIDetails>();
@IndexedEmbedded(depth = 1)
private LocalBusinessOwner businessOwner;
@OneToMany(mappedBy = "poi")
public Collection<POIDetails> getDetailsSet() {
return detailsSet;
}
@ManyToOne
@JoinColumn(name = "LBO_ID", referencedColumnName = "LBO_ID")
public LocalBusinessOwner getBusinessOwner() {
return businessOwner;
}
}
@Entity
@Indexed
@Table(name = "POI_DETAILS")
@SequenceGenerator(name = "POI_DET_SEQ", sequenceName = "POI_DETAILS_POI_DET_ID_SEQ")
public class POIDetails implements Cloneable, Serializable {
// Attributes
@DocumentId
private Long id;
@Field(index=Index.TOKENIZED, store=Store.NO)
private String name;
@Field(index=Index.TOKENIZED, store=Store.NO)
private String desc;
[...]
// Associations
@ContainedIn
private POI poi;
[...]
@ManyToOne
@JoinColumn(name = "POI_ID")
public POI getPoi() {
return poi;
}
}
@Entity
@Indexed
@DiscriminatorValue("APP_POI")
public class AppPOI extends POI implements Cloneable, Serializable {
@Field(index=Index.TOKENIZED, store=Store.NO)
private String webSite;
@Field(index=Index.UN_TOKENIZED) // Fields used for sorting must not be tokenized
private long nbBookmark;
@Field(index=Index.UN_TOKENIZED) // Fields used for sorting must not be tokenized
private long nbReview;
@Field(index=Index.TOKENIZED, store=Store.NO)
private RevisionState revisionState;
// Associations
@CollectionOfElements
@IndexedEmbedded(depth = 1)
private Collection<Review> reviewSet = new ArrayList<Review>();
@IndexedEmbedded(depth = 2)
private Category mainCategory;
@OneToMany(mappedBy = "poi")
public Collection<Review> getReviewSet() {
return reviewSet;
}
@OneToMany(mappedBy = "poi")
public Collection<GrpPOI> getGrpPoiSet() {
return grpPoiSet;
}
@ManyToOne
@JoinColumn(name="poi_ctg_main_id")
public Category getMainCategory() {
return mainCategory;
}
}
@Entity
@Indexed
@Table(name = "REVIEW")
@SequenceGenerator(name = "REVIEW_SEQ", sequenceName = "REVIEW_RW_ID_SEQ")
public class Review implements Serializable{
@DocumentId
private long id;
@Field(index=Index.UN_TOKENIZED, store = Store.YES) // Fields used for sorting must not be tokenized
private short rating;
@Field(index=Index.TOKENIZED, store=Store.NO)
private String summary;
@Field(index=Index.TOKENIZED, store=Store.NO)
private String description;
// Associations
@ContainedIn
private AppPOI poi;
@ManyToOne
@JoinColumn(name="POI_ID")
public AppPOI getPoi() {
return poi;
}
}