-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Spring - how to inject session factory for manual indexing
PostPosted: Sun May 29, 2011 11:11 am 
Newbie

Joined: Sun May 29, 2011 11:07 am
Posts: 5
Hi,

I am trying to use the mass indexer as outlined here:

http://docs.jboss.org/hibernate/search/ ... ml_single/ :

Example 1.6. Using Hibernate Session to index data

FullTextSession fullTextSession = Search.getFullTextSession(session);

fullTextSession.createIndexer().startAndWait();


My question is how, using Spring 2.5, do I inject the session factory into the spring-managed class that contains this code?

This is my class:

@Transactional
public class ManualIndexer {
private static final Logger LOGGER = Logger.getLogger(ManualIndexer.class.getName());
private SessionFactory sessionFactory;

public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}

public void index() {

LOGGER.info("Indexing everything in the DB...");

StopWatch timer = new StopWatch();
Session session = SessionFactoryUtils.getSession(sessionFactory, false);

FullTextSession fullTextSession = Search.getFullTextSession(session);
try {
timer.start();
fullTextSession.createIndexer().startAndWait();
timer.stop();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
fullTextSession.close();
}
LOGGER.info("Finished indexing after: " + timer.getLastTaskTimeMillis() + "ms");
}
}

Many thanks
Jay


Top
 Profile  
 
 Post subject: Re: Spring - how to inject session factory for manual indexing
PostPosted: Mon May 30, 2011 2:19 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi,
I'm no Spring expert, but something like that should work. You don't need the SessionFactory, any Session will do.
Are you having any errors?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Spring - how to inject session factory for manual indexing
PostPosted: Mon May 30, 2011 5:25 pm 
Newbie

Joined: Sun May 29, 2011 11:07 am
Posts: 5
Hi,

Thanks for the quick reply.

I use the SessionFactory and get the session from it as in the code. I define the factory in my bean definition as follows:

<bean id="manualIndexer" class="com.ruggeddesign.infra.search.ManualIndexer">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>

I was getting CGILib errors so I added a cgilib-nodep-2.1.3.jar to clear this up. Then my errors went away. As long as this is ok, I am happy??

Cheers
J


Top
 Profile  
 
 Post subject: Re: Spring - how to inject session factory for manual indexing
PostPosted: Mon May 30, 2011 6:30 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
yes that should be fine, Search doesn't need CGLIB but Spring might need it.
(In other words: that doesn't affect Hibernate Search's functionality, it might affect Spring but I don't know that)

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Spring - how to inject session factory for manual indexing
PostPosted: Tue May 31, 2011 5:30 am 
Newbie

Joined: Sun May 29, 2011 11:07 am
Posts: 5
Thanks for your help and fast reply

Jay


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.