-->
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: How to integrate Hibernate Search w/ Spring
PostPosted: Mon Mar 10, 2008 5:37 am 
Beginner
Beginner

Joined: Mon Aug 13, 2007 2:37 am
Posts: 22
Hi guys,

I have a web application that I developed using Hibernate, Spring and Struts.

I would like to integrate it with Hibernate Search. However, I've never used Hibernated Search before and they are not a lot of examples out there for Hibernate + Spring.

Can any one of you smarties please help me out in integrating Hibernate Search + Spring? Or point me to tutorials that will give me a start? How can I add Hibernate Search to my current configuration?

Here's my code:

Code:
<!-- Local DataSource that works in any environment -->   
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"><value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value></property>      
<property name="url"><value>jdbc:sqlserver://localhost:1433;databaseName=RX</value></property>      
<property name="username"><value>sa</value></property>   
<property name="password"><value>myP@sswrd</value></property>   
</bean>    

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource"><ref bean="dataSource" />
</property>
<property name="mappingResources">         
<list>               <value>config/BusinessCbo.hbm.xml</value>         
</list>      
</property>      
<property name="hibernateProperties">         
<props>            

<prop key="hibernate.dialect">com.PBCoreApp.hibernate.PBSQLServerDialect</prop>            
<prop key="hibernate.show_sql">true</prop>      
<prop key="hibernate.max_fetch_depth">1</prop>      
<prop key="hibernate.default_schema">RX</prop>      
</props>      
</property>   
</bean>      

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">   
<property name="sessionFactory"><ref bean="sessionFactory"/>   
</property>   
</bean>      

<bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterceptor">
<property name="sessionFactory">
<ref bean="sessionFactory"/>         
</property>   
</bean>
       
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">      
<property name="sessionFactory"><ref local="sessionFactory"/></property>   
</bean>   

<bean id="businessBSTarget" class="com.PBCoreApp.business.impl.BusinessBSImpl">
<property name="businessDao"><ref local="businessDao" /></property>
</bean>   

<bean id="businessBS" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">   
<property name="transactionManager"><ref bean="transactionManager"/></property>      
<property name="target"><ref local="businessBSTarget" /></property>
<property name="transactionAttributes">
<props>            
<prop key="find*">PROPAGATION_REQUIRED,-Exception</prop> </props>      
</property>            
</bean>   

<bean id="businessDao" class="com.PBCoreApp.dataaccess.impl.BusinessDAOImpl"><property name="hibernateTemplate">
<ref bean="hibernateTemplate"/>
</property>   
</bean>
....



My DAO class....
Code:
public class BusinessDAOImpl extends HibernateDaoSupport implements BusinessDAO
{    
public List findByBusinessId(Object businessId)
{        
List resultList =this.getHibernateTemplate().find(              
     "FROM BusinessCbo AS B "                    
     + "WHERE B.busines."                    
     + BUSINESS_ID + "= ?",                    
        businessId);                 
      return resultList; 
}
}


Thanks in advance!!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 10, 2008 3:28 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I used now the Spring + JPA + Hibernate Search + Struts approach successfully in two projects. Here are some tips:
http://hibernate.org/441.html.

I am using JPA and annotation driven configuration, but of course your xml driven configuration will work as well.

--Hardy


Top
 Profile  
 
 Post subject: Use Spring 2.5.2
PostPosted: Wed Mar 12, 2008 2:45 pm 
Newbie

Joined: Wed Mar 12, 2008 2:38 pm
Posts: 2
Location: Rochester, MN
There were some issues with Session proxy with Spring releases prior to 2.5.2.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 07, 2008 8:30 pm 
Newbie

Joined: Mon Apr 07, 2008 8:26 pm
Posts: 1
Can anyone post an example of querying using HibernateTamplate?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 09, 2008 11:45 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I don't think HSearch queries have been templetized by Spring. And I hope it will never be the case. Templates are a bad idea. Just use the straight API.

_________________
Emmanuel


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.