JPQL stands for Java Persistence Query Language. Based on the EJB Query Language (EJB QL) first introduced in EJB 2.0, the Java Persistence Query Language (JPQL) is a portable query language designed to bind SQL syntax and simple query semantics together in the form of object-oriented expression language expressions. Queries written in this language are portable and can be compiled into SQL on all major database servers. Its features are similar to native SQL statements and are fully object-oriented, accessed through class names and attributes rather than table names and table attributes. To use JPQL, you need to modify the SQL statement to be similar to HQL statement. SQL queries the database, while JPQL queries objects and attributes, and the syntax is somewhat different. For some queries that cannot be written in JPQL, it is more convenient to write them in native SQL. Here is an example, note the difference in syntax: JPQL Query @PersistenceContext protected EntityManager em; public List<Video> findVideoList1() { String hql = "from Video order by id desc"; Query query = em.createQuery(hql); List<Video> result = query.getResultList(); em.clear(); return result; } SQL Query Query the data for the last 7 days public List<Video> findVideoList2() { List<Video> result = (List<Video>) em.createNativeQuery ("select * from db_video where date_sub(curdate(), interval 6 day) <= date(date) order by date desc", Video.class) .getResultList(); return result; } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: In-depth analysis of Linux NFS mechanism through cases
>>: Source code reveals why Vue2 this can directly obtain data and methods
There are many tutorials on the Internet, and the...
Table of contents Environment Preparation start 1...
Note: This article has been translated by someone ...
1. Download the RPM package corresponding to Linu...
Events can specify the execution of SQL code once...
The mysql service is started, but the connection ...
Table of contents Preface Cause analysis and solu...
50 lines of code to change 5 skin colors, includi...
Using the image service deployed by docker stack,...
Table of contents Technology Stack Effect analyze...
<br />Original: http://www.alistapart.com/ar...
Ubuntu 15.04 opens MySQL remote port 3306. All th...
Table of contents MySQL Shell import_table data i...
This article shares with you the specific code of...