Hi,
I'm replying here to this thread because this is the only place that had mentioned something I'm seeing when I run my code.
I am trying to
index (and
retrieve in search results) a
java.util.Date property and a
java.util.Set property in my managed entity
Product:
Code:
@Entity
@Table(name = "PRODUCT")
@Indexed(index = "Product")
public abstract class Product extends BaseEntity implements Serializable {
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CREATE_DATE", updatable=false)
@Field(index = Index.UN_TOKENIZED, store = Store.YES)
@DateBridge(resolution = Resolution.MINUTE)
private Date createDate;
@OneToMany(cascade = { CascadeType.ALL, CascadeType.REMOVE })
@Cascade({org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@JoinColumn(name = "PRODUCT_ID", nullable = false)
@IndexedEmbedded(depth = 2)
private Set<LocaleAwareMetadata> allLocaleAwareMetadata =
new HashSet<LocaleAwareMetadata>();
}
// Entity LocaleAwareMetadata:
@Entity
@Table(name = "METADATA")
@Indexed(index = "LocaleAwareMetadata")
@ClassBridge(
name = "display_title_studio_network",
index = Index.UN_TOKENIZED,
store = Store.YES,
impl = LocaleAwareMetadataClassBridge.class)
public class LocaleAwareMetadata extends BaseEntity implements Serializable {
// LocaleAwareMetadataClassBridge combines some properties for indexing
// properties omitted
}
// In my service impl:
Session session = null;
try {
// Spring's HibernateDaoSupport.getSessionFactory()
session = getSessionFactory().openSession();
FullTextSession fullTextSession = Search
.createFullTextSession(session);
fullTextSession.setFlushMode(FlushMode.MANUAL);
fullTextSession.setCacheMode(CacheMode.IGNORE);
Transaction tx = fullTextSession.beginTransaction();
ScrollableResults results =
fullTextSession.createCriteria(Product.class)
.setFetchMode("allLocaleAwareMetadata", FetchMode.JOIN)
.scroll(ScrollMode.FORWARD_ONLY);
int index = 0;
while (results.next()) {
index++;
fullTextSession.index(results.get(0));
if (index % 10 == 0) {
//clear every batchSize since the queue is processed
fullTextSession.clear();
}
}
tx.commit();
}
catch (HibernateException e) {
logger.error("Caught an exception while performing indexing", e);
}
if (null != session) {
session.close();
}
When I run the indexing code in my service implementation, I get the following stack traces:
Code:
17:40:28-700 ERROR te.LazyInitializationException failed to lazily initialize a collection of role: com.connect.vine.product.Product.allCountryAwareMetadata, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.connect.vine.product.Product.allCountryAwareMetadata, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:163)
at org.hibernate.search.engine.DocumentBuilder.buildDocumentFields(DocumentBuilder.java:554)
at org.hibernate.search.engine.DocumentBuilder.getDocument(DocumentBuilder.java:514)
at org.hibernate.search.engine.DocumentBuilder.addWorkToQueue(DocumentBuilder.java:431)
at org.hibernate.search.backend.impl.BatchedQueueingProcessor.prepareWorks(BatchedQueueingProcessor.java:122)
at org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization.beforeCompletion(PostTransactionWorkQueueSynchronization.java:44)
at org.hibernate.transaction.JDBCTransaction.notifyLocalSynchsBeforeTransactionCompletion(JDBCTransaction.java:228)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:109)
at com.connect.vine.search.SearchManagerImpl.index(SearchManagerImpl.java:181)
(snip...)
17:40:28-935 ERROR te.transaction.JDBCTransaction exception calling user Synchronization
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.connect.vine.product.Product.allCountryAwareMetadata, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:163)
at org.hibernate.search.engine.DocumentBuilder.buildDocumentFields(DocumentBuilder.java:554)
at org.hibernate.search.engine.DocumentBuilder.getDocument(DocumentBuilder.java:514)
at org.hibernate.search.engine.DocumentBuilder.addWorkToQueue(DocumentBuilder.java:431)
at org.hibernate.search.backend.impl.BatchedQueueingProcessor.prepareWorks(BatchedQueueingProcessor.java:122)
at org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization.beforeCompletion(PostTransactionWorkQueueSynchronization.java:44)
at org.hibernate.transaction.JDBCTransaction.notifyLocalSynchsBeforeTransactionCompletion(JDBCTransaction.java:228)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:109)
at com.connect.vine.search.SearchManagerImpl.index(SearchManagerImpl.java:181)
(snip...)
17:40:29-154 ERROR ations.common.AssertionFailure an assertion failure occured (this may indicate a bug in Hibernate)
org.hibernate.annotations.common.AssertionFailure: Access a Sealed WorkQueue whcih has not been sealed
at org.hibernate.search.backend.WorkQueue.getSealedQueue(WorkQueue.java:48)
at org.hibernate.search.backend.impl.BatchedQueueingProcessor.performWorks(BatchedQueueingProcessor.java:130)
at org.hibernate.search.backend.impl.PostTransactionWorkQueueSynchronization.afterCompletion(PostTransactionWorkQueueSynchronization.java:50)
at org.hibernate.transaction.JDBCTransaction.notifyLocalSynchsAfterTransactionCompletion(JDBCTransaction.java:243)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:121)
at com.connect.vine.search.SearchManagerImpl.index(SearchManagerImpl.java:181)
(snip...)
I can't figure out what I'm doing wrong - if it's my annotations or indexing code. Can someone help?
Thanks in advance!
-Frank