Answer the question
In order to leave comments, you need to log in
How to compose a Full-Text HQL query containing SQL contains?
It is necessary to search through a web service in a full-text field. HQL does not support the Contains and ContainsTable SQL predicates.
Approximately this SQL query is converted to HQL:
select * from test_docs where Contains(xxtext,'Boaz')
Answer the question
In order to leave comments, you need to log in
The problem was solved like this.
Create a SQL function:
USE [dbName]
GO
/****** Object: UserDefinedFunction [dbo].[funcFullText] Script Date: 11/27/2014 1:12:11 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <Description, ,>
-- =============================================
ALTER FUNCTION [dbo].[funcFullText]
(
-- Add the parameters for the function here
@query varchar (250), @ID varchar (45)
)
RETURNS BIT
AS
BEGIN
-- Declare the return variable here
DECLARE @Result BIT
DECLARE @SQL INT
select @SQL = count(*) from test_docs where Contains(xxtext,@query) and SYSROWID = @ID
IF @SQL > 0 SET @Result = 1 ELSE SET @Result = 0
-- Return the result of the function
RETURN @Result
END
hql = " from test_docs where dbo.funcFullText('" + txtSqlQuery.Text + "',SYSROWID) = true";
saWsPropertyValueArray[] result = archiveService.search(token, hql);
Hibernate works great with SQL, do this:
Query query = session.createSQLQuery("select * from test_docs where Contains(xxtext,'Boaz')")
.addEntity(TestDoc.class);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question