2

My goal is to use the MSSQL Fulltext Function with HQL. For what case I wrote a specific SQLFunction mapping the my "fulltext" function to the contains function.

However, the problem is that in HQL (it seems) I have to explicity use a return type, which the MSSQL Contains functions does not use or accepts.

This is how it works in MSSQL:

select distinct id from content c where CONTAINS(c.content, 'p')

This is my idea of using it in HQL:

select id from Content c  where fulltext(c.content, 'p') 

This does not work, since HQL needs a return type. For example this will parse in HQL:

select id from Content c  where fulltext(c.content, 'p') = true

And it will generate as SQL:

select distinct id from content c where CONTAINS(c.content, 'p') = 1

which will not work in MS SQL.

My ideas are so far but what does not seem possible in this setup:

  1. Make hibernate parse functions with no return value (Hibernate does not support this in my version used)
  2. Trying to mix HQL and SQL (also does not seem to work)

Anyone got another idea or help?

My Hibernate Version used is 3.2.6ga and MSSQL Server 2008.

Torsten
  • 51
  • 1
  • 6

2 Answers2

3

I found a way what works for me.

Instead of generating

CONTAINS(a,b) 

it will generate

CONTAINS(a,b) AND 1

And in conjunction with the HQL Query

fulltext(a,b) = true

It will result in:

CONTAINS(a,b) AND 1 = 1 

And it works.

Torsten
  • 51
  • 1
  • 6
1

Native Query might help

NimChimpsky
  • 43,542
  • 55
  • 186
  • 295