Questions tagged [native-sql]
77 questions
83
votes
1 answer
Difference between query, native query, named query and typed query
What are the differences between a query, a native query, a named query and a typed query? Does the 'alone-standing' query even exist, or is it just an abbreviation? In my mind, a native Query is a query written in simple sql, whereas a named query…

Chris311
- 3,794
- 9
- 46
- 80
38
votes
1 answer
getting result set into DTO with native SQL Query in Hibernate
I have a query like below
select f.id, s.name, ss.name
from first f
left join second s on f.id = s.id
left join second ss on f.sId = ss.id
If I could use HQL, I would have used HQL constructor syntax to directly populate DTO with the result…

Reddy
- 8,737
- 11
- 55
- 73
23
votes
5 answers
Hibernate Native SQL Query retrieving entities and collections
This is my situation, I have two basic POJO's which I've given a simple hibernate mapping :
Person
- PersonId
- Name
- Books
Book
- Code
- Description
My SQL Query returns rows that look like this :
PERSONID NAME CODE…

Ben
- 532
- 2
- 4
- 12
15
votes
2 answers
How to configure default database schema for native queries in pure JPA?
Our situation is as follows:
We use (mustly pure) JPA for persistence in our enterprise application.
Due to performance reasons, we use a number of fairly complicated native queries here an there.
When accessing the database (Oracle 11g), we use a…

lexicore
- 42,748
- 17
- 132
- 221
14
votes
3 answers
Native SQL query for an Hibernate entity using @Formula results in NullPointerException
I've got an simple Hibernate entity for which I use the @Formula annotion:
@Id
private Long id;
private String name;
@Formula("(select count(f.*) from foo f where f.id = id)")
private long bar;
When I try to load an entity with a native SQL…

mikrobi
- 291
- 1
- 3
- 11
10
votes
1 answer
When should a person use native queries with JPA 2.0 instead of JPQL or CriteriaBuilder?
I am very confused about when and when not to use native queries in JPA 2.0. I was under the impression that using native queries could cause me to get out of sync with the JPA cache. If I can accomplish the same thing with a JPQL or…

user1148956
- 303
- 1
- 3
- 9
5
votes
0 answers
Hibernate Native SQL Query retrieving multiple entities in join
Referencing with this answer to this correlated thread,
the trick posted by ehrhardt works fine.
But, what I have to do if I have to join with multiple entities? for example:
List peopleWithBooks = session.createSQLQuery(
"select {p.*},…

fl4l
- 1,580
- 4
- 21
- 27
5
votes
1 answer
How To Utilize Doctrine2 Type Conversion on Native Query COLUMNS
Could not find anything on this-- seems like it should be straight forward though.
So the example the Doctrine2 docs give for type conversion on bound parameters looks like this:
$date = new \DateTime("2011-03-05 14:00:21");
$stmt =…

Peter M. Elias
- 1,204
- 10
- 22
4
votes
1 answer
Hibernate = Column not found
I am running an aggregate function in java through hibernate and for some reason it is giving me this error:
INFO Binary:182 - could not read column value from result set: l_date; Column 'l_date' not found.
When I run the MySQL query the column…

IamBanksy
- 591
- 3
- 9
- 13
4
votes
1 answer
Spring data - insert data depending on previous insert
I need to save data into 2 tables (an entity and an association table).
I simply save my entity with the save() method from my entity repository.
Then, for performances, I need to insert rows into an association table in native sql. The rows have a…

Truche
- 523
- 1
- 5
- 19
4
votes
0 answers
Cannot Create Temporary Table using Hibernate
I cannot able to create temporary table using hibernate here is my code
getSession().beginTransaction();
String queryString1 = "CREATE TEMPORARY TABLE sage_temp_table(CRMID VARCHAR(60),POPAmountPaid DECIMAL(14,2)) ";
…

Abhishek Kumar
- 315
- 1
- 4
- 10
4
votes
1 answer
hibernate throwing: An unexpected token "" was found following ""
I have a native SQL query that i want to run through hibernate, but throws an error:
org.hibernate.exception.SQLGrammarException:
could not execute native bulk manipulation query
Caused by:
com.ibm.db2.jcc.am.SqlSyntaxErrorException: An unexpected…

cianBuckley
- 1,264
- 2
- 18
- 25
3
votes
1 answer
How to define table aliases for joined tables in plain SQL queries?
I have an entity that is mapped with a element like this:

cremor
- 6,669
- 1
- 29
- 72
3
votes
1 answer
Batch insertion using hibernate native queries
Below is the code executing insert query in iterations :
session = sessionFactory.getCurrentSession();
for (SampleBO items : listCTN) {
try {
query = session
…

Joginder Pawan
- 659
- 3
- 10
- 19
3
votes
1 answer
Why to use the Hibernate Query addScalar method?
I have a query in native sql , something like :
SQLQuery query = session.createSQLQuery("select emp_id, emp_name, emp_salary from Employee");
the query result can be used to set the employee object .
On the similar lines , i have the same query…

jayendra bhatt
- 1,337
- 2
- 19
- 41