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
This article shares the specific code of React+ts...
JavaScript clothing album switching effect (simil...
In cells, dark border colors can be defined indiv...
Preface In front-end development, we often encoun...
The <marquee> tag is a tag that appears in ...
Copy code The code is as follows: <!DOCTYPE ht...
Use JavaScript to implement a web page clock. The...
The previous article introduced the installation ...
Aggregate functions Acts on a set of data and ret...
MySQL is a free relational database with a huge u...
After entering yum in linux, the prompt: -bash: /...
I encountered a small problem today and struggled ...
"/" is the root directory, and "~&...
Table of contents Cross-domain reasons JSONP Ngin...
1. In IE, if relative positioning is used, that is...