Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » append Postgres Full Text Search expression after having CriteriaQuery(How to append the native where expression for use the Full Text Search on Postgres)
append Postgres Full Text Search expression after having CriteriaQuery [message #1272703] Tue, 18 March 2014 14:44 Go to next message
Clovis Wichoski is currently offline Clovis Wichoski
Messages: 7
Registered: March 2012
Junior Member
Hi,

I have a scenario where the user create some filters using CriteriaQuery, but one of that filter was a free search field, I wish to get the EclipseLink generated SQL and append the a String on that SQL, but the DatabaseQuery returns null from CriteriaQuery, here is the algorithm idea:

CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery cq = cb.createQuery();

//populates cq suppressed content

TypedQuery q = em.createQuery(cq);
String generatedSQL = q.unwrap(JpaQuery.class).getDatabaseQuery().getSQLString();
String nativeSQL = generatedSQL + " AND buscaLivre @@ to_tsquery('ELX')";


ps: buscaLivre is the field that allow the full text search.

This dont works as the content of generatedSQL is null then the nativeSQL string get the value "null AND buscaLivre @@ to_tsquery('ELX')".

I tried to find some way to inject this expression on where part of criteria, but dont found a native() method, if that exists that would be great, but as dont exists I tried to concat SQL strings, any way to get that SQL? anyone have a better approach for that?

best regards

Clóvis
Re: append Postgres Full Text Search expression after having CriteriaQuery [message #1274576 is a reply to message #1272703] Fri, 21 March 2014 17:04 Go to previous message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1019
Registered: July 2009
Senior Member
http://wiki.eclipse.org/EclipseLink/FAQ/JPA#How_to_get_the_SQL_for_a_Query.3F details what you need to get the SQL. What is missing is the prepareCall to generate the SQL string in the query.

If you have parameters, you will need to use getTranslatedSQLString if you want the ? replaced with parameter values.
Previous Topic:Example of leftJoin?
Next Topic:Multi tenancy - NullPointerException
Goto Forum:
  


Current Time: Tue Sep 16 09:45:59 GMT 2014

Powered by FUDForum. Page generated in 0.01572 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software