function « Query « JPA Q&A





1. Hibernate HQL Query : How to properly use ANY function in where clause?    stackoverflow.com

I'm struggling to understand my error in an HQL query:

public List<Pats> getIds(List<String> patIds) {
    Session session = getSession();
    String hql = "from OurPats where patId ...

2. Incorrect usage of STR() function in HQL    stackoverflow.com

With this HQL query:

SELECT DISTINCT fs FROM FileStatus fs WHERE UPPER(STR(fs.filePath)) LIKE :FILE_PATH
I get:
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:637)
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:74)
and with my ...

3. JPA Query MONTH/YEAR functions    stackoverflow.com

How can I write a JPA query using MONTH function just like sql query?

@NamedQuery(name="querybymonth", query="select t from table1 t where MONTH(c_Date) = 5")
When I use the above pattern for query, I ...

4. How to construct advanced Hibernate Query with OR and summarize functions    stackoverflow.com

I have a rather complex query which works in SQL, but I would like to express this in HQL for portability. I'm going to fetch a user configured preference value if ...

5. hql rank function, select in select causes antlr exception    stackoverflow.com

I'm trying to make the following hql query work, but with no success. I'm trying to find out what rank has a specific user, dependent on a field value in a ...

6. Is it possible to have a sub-select in a HQL dateAdd function?    stackoverflow.com

I am having some trouble with a HQL dateAdd function in Hibernate 3. In the following code I want to get all matters which have a lastTimeDate greater then the maximum deadline ...

7. How to use in hibernate user-defined-function done is sql (and still have pagination)    stackoverflow.com

I need to run a query that uses a function I created on the Oracle SQL(10g) database.

  • I've seen that Hibernate supports some aggregate functions (avg, sum, min, max and some forms ...

8. JPA Criteria API. Query with sql function call which takes parameters    stackoverflow.com

I'm trying to construct this query using Criteria typesafe API:

select * from xxx_table xxx where CALC_DISTANCE(xxx.latitude, xxx.longitude, :lat, :lng) < :dist

CALC_DISTANCE definded PL/SQL function:  
FUNCTION calc_distance(  
 ...

9. [JPA/TOPLINK] is the function "lower" supported in "order by" clause? if not, how....    coderanch.com

In EJB-QL I can use lower() or upper() in where clause. But there is always a parse exception thrown when i tried to use it in main clause or order by clause. works: select s from Student s where lower(s.name) like 'm%' exception thrown: select s from Student s where s.name like 'm%' order by lower(s.name) OR ----------------------------------------------------------------------------Why i am asking ...





10. Problem calling Query using a function ...    forum.hibernate.org

I have a function that calculates the distance between 2 strings. Doing so with various fields, I can calculate whether 2 users are the same/similar or not, by doing this in the "MS SQL Server Management Studio" (see discussion here). Code: with Search_distances as ( select dbo.LEVENSHTEIN (USEARCH.logonuid, :logonuid) distance_logonuid, dbo.LEVENSHTEIN (USEARCH.firstname, ...

11. Using Informix TODAY built-in function in where clause    forum.hibernate.org

I'm using Hibernate 3.3.2GA against an Informix 11.5 database. Records are begin- and end-dated in this database, so I want to define where clauses for a few classes to limit the retrieval to only active records, which would look like this: Code:

13. order by clause with user-defined function    forum.hibernate.org

We have a Family Hibernate Entity. This entity has(among others) 4 booleans properties. When retrieving the Families from the Postgres 8.4 DB, it is required that the List of families be ordered by sum of the boolean properties. There are 2 other fields in the order by criterion. Eg Code: select fam.a, fam.b, fam.c, fam.d, fam.e from family fam ...

14. scalar functions in native SQL queries? (to_char)    forum.hibernate.org

I wonder if anyone can tell me how to use a function such as to_char in Oracle in a native SQL query? I want to execute the following query: Select sum(t.personligtmeddelandetyp) as PERSONLI2_0_, to_char(t.skapatdatum, 'YYYY') as AVSENDARE0_, to_char(t.skapatdatum, 'MM') as MOTTAGARE0_ from personligtmeddelandesok t group by to_char(t.skapatdatum, 'YYYY'), to_char(t.skapatdatum, 'MM') It works fine when a execute it in a SQL*plus. When ...

16. Query parser complaints about SQL functions?    forum.hibernate.org

This was previously mentioned in December 2003 in this thread here: http://forum.hibernate.org/viewtopic.php?t=926173 Basically, the query parser complains about certain common sql functions, particularly those to do with full-text searching. In the example above, the function was mySQL's match() function. In my problem, it is the MS-SQL equivilent, contains(). Both the match() and contains() function take two arguments, which seems to be ...





17. Order By problem with Oracle/Aggregated functions with MySql    forum.hibernate.org

Hibernate 2.14 Oracle 8.17 MySQL 3.23.49 I am having problems with ORDER BY with Oracle and MySQL I am attempting to use the following HQL. select new RankedCompetencyView( avg(cp.score), a.name, comp.description) from Candidate c join elements(c.candidateProfiles) cp join c.nextPosition np join np.currentGrade a join cp.competency comp group by a, comp order by a // avg(cp.score)

18. Find query function .... Question    forum.hibernate.org

20. hql and sql functions in group by    forum.hibernate.org

release : last hibernate3 cvs (today) I play with hql and group by and this query : select substr(human.nickName,1,3),count(*) from Human human group by substr(human.nickName,1,3) work with old parser, but doesn't work with new (AST) parser I try next workaround in hql.g (line 332) ( "by"! expression ( COMMA! expression )* )? except : ( "by"! path ( COMMA! path )* ...

21. query and bit functions    forum.hibernate.org

22. HQL query using functions    forum.hibernate.org

HI, Thanks for your help, I still didn't get it to work. Previously I have tried what you suggested from myobject as analias where analias.columnA = 1 and analias.columnB IN(my_function()) but this throws a JDBC exception. ORA-00932: inconsistent datatypes: expected NUMBER got IDS_ARRAY I know that the end of the sql query should look something like this select * from table(my_function()) ...

24. Queries on Oracle Functions    forum.hibernate.org

Hello all, I am trying to do a query from an Oracle function and am tearing my hair out trying to figure out the answer. I am using Hibernate v2 and want to find the result from the following: Code: SELECT pkgName.pkgFunction FROM dual WHERE rownum = 1 Basically there is a Oracle Package that contains a Function I need to ...

25. How to order agregate functions?    forum.hibernate.org

26. Using distinct function in SQLQuery with other MySQL funcs    forum.hibernate.org

The second approach I mentioned yeilds the following error: "column id0_ not found". I have seen this error before and posted it on the forums. Various techs have attempted to answer this question, but I am still at a loss as to how I can format this style of query. Again, all I want to do is execute the following query, ...

27. Named query using internal function    forum.hibernate.org

Hi, guys. New to the forum. I have a problem using a named query, located in the class mapping file. Here's the mapping file: Code: ...

28. Realod function in a join query    forum.hibernate.org

29. Using Mysql function AES_DECRYPT in select clause of HQL    forum.hibernate.org

Hi I am using the hibernate 3.2 alpha 2 I am getting an error using the AES_DECRYPT MySQL function in select clause of the HQL. The same function i am able to use in the order by clause of the HQL. Am i missing something or this function is not supported in the select clause. Reply is greatly appreciated. Here is ...

30. Nullpointer while calling function from named query    forum.hibernate.org

Following exception occurs while calling a function that returns SYS_REFCURSOR {? = UNSET_PROD_IMPORTED_STATUS(?) } Any idea why this is happening? java.lang.NullPointerException at oracle.jdbc.driver.T4C8Oall.getNumRows(T4C8Oall.java:728) at oracle.jdbc.driver.T4CCallableStatement.execute_for_rows(T4CCallableStatement.java:787) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1027) at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2885) at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:2976) at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4103) at org.hibernate.dialect.Oracle9Dialect.getResultSet(Oracle9Dialect.java:309) at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:127) at org.hibernate.loader.Loader.getResultSet(Loader.java:1269) at org.hibernate.loader.Loader.doQuery(Loader.java:391) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218) at org.hibernate.loader.Loader.doList(Loader.java:1593) at org.hibernate.loader.Loader.list(Loader.java:1577) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:112) at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1414) at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:153) ...

32. Function calls in Criteria-based queries    forum.hibernate.org

Date now = ... (date with time truncated) ... Integer resultCount = (Integer)session.createCriteria( MyEntity.class ) .add( Restrictions.sqlRestriction( "date_between_range( ?, {alias}.active_start_date, {alias}.active_end_date ) = ?", new Object[] { now, 1 }, new Type[] { Hibernate.DATE, Hibernate.INTEGER } ) ) .setProjection( Projections.rowCount() ) .uniqueResult();

33. hql: imbricated functions in select clause    forum.hibernate.org

The problem was the TIME_TO_SEC function... Considering the error message I got first time, I assumed the problem was that you can't open a new paranthesis inside a pair of paranthesis (the imbricated function). I modified the query and I got the exception below. So you were right... javax.servlet.ServletException: undefined alias: TIME_TO_SEC [ select viz.cliId, TIME_TO_SEC(viz.vizDataIn) from com.sm.sfa.mapping.Sfa_vizite as viz where ...

34. double JOIN / GROUP BY / AGREGATE Function ...    forum.hibernate.org

SEQ_SHIP_ID ... ...

35. Hibernate Criteria API + Order by native SQL function    forum.hibernate.org

Hibernate version: 3.2.1 Hi, Since I cannot find anything about how to achieve my goal in the documentation, I am trying to forums.... So, the context of the problem : in pure SQL, I have something like : select * from city where gis_distance(..) <= 50000 ORDER BY gis_distance(...); gis_distance is a DMBS-specific function, and (..) are its parameters. So, I ...

36. Can I include a Java function in an hql query?    forum.hibernate.org

Bear with me... This isn't as odd as it sounds... I want to write an hql query like this: "from Person p where p.name='Smith' and p.age > 20" where 'name' is a standard Hibernate mapped and persisted field but 'age' is programmatically generated. It looks like I need to map the 'age' field in my hbm mapping in order to include ...

37. Need help about query with a stored function    forum.hibernate.org

hello guys!!! I'm newbie in hibernate and my english very bad. But I'll try it. I need run a query with a stored function. The stored function is : CREATE OR REPLACE FUNCTION Civ_Genera_Xml_PROFE (PID_PROFESIONAL PROFESIONALES.ID_PROFESIONAL%TYPE, PUSUARIO VARCHAR2, PCODERROR OUT NUMBER, PTEXTERROR OUT VARCHAR2 ) RETURN NUMBER IS my question is: How I can do to mapping the create query into ...

38. Group by functionality with Criteria    forum.hibernate.org

Hi, I'm very new to Hibernate and I have a question about Criteria and group by. I have a little test project up with a table that contains some data. Let's say it is possible to have duplicate entries for certain properties (in my case, usernames -- just a test :D). Anyway, I want to select rows such that no duplicate ...

39. Registering functions to use native sql queries    forum.hibernate.org

40. 'concat' or 'group_concat' functions in HQL's SELECT clause    forum.hibernate.org

Hi, I have a requirement where I need to use 'concat' and 'group_concat' functions in HQL's SELECT clause but as I use them in HQL I get following errors a) "Undefine alias group_concat" b) "Undefined alias concat" The query I am using is: SELECT group_concat( concat(E.firstName, ':', a.lastName) ) FROM Employee E Group By E.department Are "concat" and "group_concat" functions available ...

41. wish to use external sql-query with Oracle Analytic function    forum.hibernate.org

It's actually reasonably easy, if you're willing to fiddle about getting the names right!!! Just use nativeQuery.addEntity(Entity.class); As long as the field names are exact, it should work. My example uses annotations however, so not sure how this pans out in standard hibernate. An example, access code first... public List jon(){ Session session = (Session) getJpaTemplate().getEntityManagerFactory().createEntityManager().getDelegate(); SQLQuery q = session.createSQLQuery(" select ...

42. NVL function usage in Order.asc()    forum.hibernate.org

Thaks for the post. I am using oracle 10g database. This DB supports NVL. I see the same issue with other oracle functions like decode also. I never used dialect. If possible could you please provide more infomation on registering function or provide the sample code. It would be of great help. Thanks.

43. Calling oracle function from hibernate as named query    forum.hibernate.org

Hi, I am trying to execute a named query having a call to an oracle function. The following is the mapping { ? = call api.test_fn(:i_application_id) } To execute List list = ...