Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Statements about JPQL

 
Nikhil Jain
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Identify FALSE (i.e. INCORRECT) statements about JPQL.

1. It is vendor independent.
2. JPQL queries are compiled into the database specific SQL queries by the container.
3. It can accomodate complex joins involving multiple tables.
4. It can be used to update entity beans.
5. It can be used to insert new rows into the database.
6. It can be used to select values only from tables that have been mapped to the abstract persistent schema.

The answers are 6

// Why is the answer not 5.
It is always possible to select values from tables that have not been mapped with abstract persistent schema. This is done using createNativeQuery.

This can be definately used to insert new rows using persist???
 
Nikhil Jain
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The explanation given to 5 was

Insert statements are not supported by JPQL. New rows can be created in the database using em.persist() operation.

The exp given to 6 was

The domain of a JPQL query consists of the abstract schema types of all entities that are defined in the same persistence unit. Thus, arbitrary tables cannot be accessed using JPQL.

Please help!!!
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is always possible to select values from tables that have not been mapped with abstract persistent schema. This is done using createNativeQuery.

createNativeQuery is used with native SQL queries, not JPQL. Remember that JPQL is not SQL. With JPQL, only entities from the abstract persistent schema can be retrieved.

And in JPQL, there is no insert statement. You're mixing it again with native SQL.
 
Nikhil Jain
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But the insert options looks so confusing. It technically inserts it into database table. The syntax used is persist method. When I read the statement, it never occured to me that it was talking about insert statement
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the answer is: em.persist() is not part of JPQL.
 
Vinay Nath
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am confused, is the answer 5 or 6???

I think its 5 because 6 sounds like a valid statement.
 
Nikhil Jain
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The 5/6 are quite confusing. Any what I gather from here is, that this question talks about JPQL. So things in em.createQuery(JPQL), where JPQL has to be something related to our schemas. right?

There is also createNativeQuery which does not expect JPQL, it requires native queries.

In terms of these, JPQL does not have insert statement as such.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic