Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring Autowiring + Hibernate Search
    text
    copied!<p>I am trying to inject a hibernate session to use with hibernate search and am having trouble figuring out how to setup the spring beans for hibernate search. I am aware that spring does not support hibernate search. I had this working before i decided to use hibernateDAO. Any suggestions would be much appreciated.</p> <pre><code>public class RestaurantDAOImpl extends HibernateDaoSupport implements RestaurantDAO{ public String getDishResults(final String query, final String location){ return getHibernateTemplate().execute( new HibernateCallback&lt;String&gt;() { @Override public String doInHibernate(Session session) throws HibernateException, SQLException { FullTextSession fullTextSession = Search.getFullTextSession(session); fullTextSession.beginTransaction(); QueryBuilder qBuilder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity( Dish.class ).get(); Query luceneQuery = qBuilder.keyword() .onFields("dishName").matching("Burger") .createQuery(); ... return // code that generates json result based on hibernate search }); } } </code></pre> <p><strong>spring context</strong></p> <pre><code>&lt;!-- Hibernate SessionFactory --&gt; &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt; &lt;property name="dataSource"&gt; &lt;ref local="dataSource" /&gt; &lt;/property&gt; &lt;property name="configLocation"&gt; &lt;value&gt;hibernate.cfg.xml&lt;/value&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt; &lt;property name="hibernateProperties"&gt; &lt;props&gt; &lt;!-- &lt;prop key="hibernate.hbm2ddl.auto"&gt;create&lt;/prop&gt; --&gt; &lt;prop key="hibernate.connection.pool_size"&gt;1&lt;/prop&gt; &lt;prop key="hibernate.show_sql"&gt;false&lt;/prop&gt; &lt;prop key="hibernate.connection.autocommit"&gt;true&lt;/prop&gt; &lt;!--MySQL --&gt; &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt; &lt;prop key="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/prop&gt; &lt;prop key="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/database&lt;/prop&gt; &lt;prop key="hibernate.connection.username"&gt;root&lt;/prop&gt; &lt;prop key="hibernate.connection.password"&gt;&lt;/prop&gt; &lt;/props&gt; &lt;/property&gt; &lt;property name="annotatedClasses"&gt; &lt;list&gt; &lt;value&gt;com.bytebite.entities.Restaurant&lt;/value&gt; &lt;value&gt;com.bytebite.entities.Dish&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor" autowire="byName" /&gt;&lt;!--sessionFactory will get autowired --&gt; &lt;bean id="restaurantDAOTarget" class="com.bytebite.dao.RestaurantDAOImpl" autowire="byName" /&gt;&lt;!--sessionFactory will get autowired --&gt; &lt;bean id="RestaurantDAO" class="org.springframework.aop.framework.ProxyFactoryBean"&gt; &lt;property name="proxyInterfaces"&gt; &lt;value&gt;com.bytebite.dao.RestaurantDAO&lt;/value&gt; &lt;/property&gt; &lt;property name="interceptorNames"&gt; &lt;list&gt; &lt;value&gt;hibernateInterceptor&lt;/value&gt; &lt;value&gt;restaurantDAOTarget&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p></p> <p>And i have to somehow reference these (which were in hibernate.cfg.xml). Could I connect the hibernate context to hibernate.cfg.xml? would that help?</p> <p><strong>hibernate.cfg.xml</strong> (what remains of it anyway. where should i put this?)</p> <pre><code> &lt;!-- Hibernate Search --&gt; &lt;property name="hibernate.search.default.directory_provider"&gt;org.hibernate.search.store.FSDirectoryProvider&lt;/property&gt; &lt;property name="hibernate.search.default.indexBase"&gt;/Users/amandacanyon/Bytebite/Bytebite/.luceneIndex&lt;/property&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload