2011-08-17 6 views
1

は私が休止状態の検索で使用するHibernateセッションを注入しようとしていると、休止状態の検索のためにどのようにセットアップ春の豆を考え出す問題を抱えています。私は、春は休止状態の検索をサポートしていないことを認識しています。私はhibernateDAOを使用することに決めた前に、この作業をしました。どんな提案も大歓迎です。春オートワイヤリング+ Hibernateの検索

public class RestaurantDAOImpl extends HibernateDaoSupport implements RestaurantDAO{ 

    public String getDishResults(final String query, final String location){ 
     return getHibernateTemplate().execute(new HibernateCallback<String>() { 
      @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 
     }); 
    } 

} 

ばねコンテキスト

<!-- Hibernate SessionFactory --> 
<bean id="sessionFactory" 
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
    <property name="dataSource"> 
     <ref local="dataSource" /> 
    </property> 
    <property name="configLocation"> 
     <value>hibernate.cfg.xml</value> 
    </property> 
</bean> 
<bean id="sessionFactory" 
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
    <property name="hibernateProperties"> 
     <props> 
      <!-- <prop key="hibernate.hbm2ddl.auto">create</prop> --> 
      <prop key="hibernate.connection.pool_size">1</prop> 
      <prop key="hibernate.show_sql">false</prop> 
      <prop key="hibernate.connection.autocommit">true</prop> 

      <!--MySQL --> 
      <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> 
      <prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop> 
      <prop key="hibernate.connection.url">jdbc:mysql://localhost:3306/database</prop> 
      <prop key="hibernate.connection.username">root</prop> 
      <prop key="hibernate.connection.password"></prop> 

     </props> 
    </property> 
    <property name="annotatedClasses"> 
     <list> 
      <value>com.bytebite.entities.Restaurant</value> 
      <value>com.bytebite.entities.Dish</value> 
     </list> 
    </property> 

</bean> 

<bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor" 
    autowire="byName" /><!--sessionFactory will get autowired --> 

<bean id="restaurantDAOTarget" class="com.bytebite.dao.RestaurantDAOImpl" 
    autowire="byName" /><!--sessionFactory will get autowired --> 

<bean id="RestaurantDAO" class="org.springframework.aop.framework.ProxyFactoryBean"> 
    <property name="proxyInterfaces"> 
     <value>com.bytebite.dao.RestaurantDAO</value> 
    </property> 
    <property name="interceptorNames"> 
     <list> 
      <value>hibernateInterceptor</value> 
      <value>restaurantDAOTarget</value> 
     </list> 
    </property> 
</bean> 

iは何とか(hibernate.cfg.xmlであった)、これらを参照しなければなりません。私はがhibernate.cfg.xmlするHibernateのコンテキストを接続してもらえますか?それが助けになるだろうか?

hibernate.cfg.xmlの(とにかくそれの残るもの。ここで、iはこれを入れてください)

<!-- Hibernate Search --> 
    <property name="hibernate.search.default.directory_provider">org.hibernate.search.store.FSDirectoryProvider</property> 
    <property name="hibernate.search.default.indexBase">/Users/amandacanyon/Bytebite/Bytebite/.luceneIndex</property> 

答えて

2

はhibernate.cfg.xmlの性質からして何をすべきかあなたの問題ですか?それは<property name="hibernateProperties">は、工場Bean内のためにあるものです。あなたは他のすべてのプロパティをそこに置きます。これらの最後の2つを追加すると何かが壊れると言っていますか?あなたが本当にしたい場合はsetConfigLocation()で休止状態の設定を参照するために、工場Beanを伝えることができますが、単に春の設定にそれらのプロパティを移動すると、まったく同じことを達成する必要があります。

+0

私は以下のコードでセッションファクトリBeanにそれらを移動しようとしましたが、それは仕事をdidntの。それは単純支持または私は間違った構文を使用した場合波平場合、私は必ず波平。 –

+0

<プロパティ名= "hibernate.search.default.directory_provider"> org.hibernate.search.store.FSDirectoryProvider <プロパティ名= "hibernate.search.default.indexBase"> /ユーザ/ amandacanyon/Bytebite/Bytebite/.luceneIndex Beanのプロパティを設定することになる –

+0

。 'hibernateProperties'プロパティの中の'

関連する問題