Hql functions and hql Functions
Serial number
Function Name
Description
Type
Supported
Usage
Remarks
1
ABS (n)
Take absolute value
Mathematical functions
JPAQL HQL
ABS (column_name [numeric object attributes])
2
SQRT (n)
Take the square root
Mathematical functions
JPAQL
following code:Customer customer= (Customer) Session.load (Customer.class, "1");Query query=session.createquery ("From Order order where order.customer=:customer");Query. SetProperties ("Customer", customer);List list=query.list ();The code above generates an SQL statement similar to the following:Select * from order where customer_id= ' 1 ';E, the advantages of using binding parameters:Why do we use binding named parameters? The existence of any one thing has its value, specific to the binding
code:Customer customer= (Customer) Session.load (Customer.class, "1");Query query=session.createquery ("From Order order where order.customer=:customer");Query. SetProperties ("Customer", customer);List list=query.list ();The code above generates an SQL statement similar to the following:Select * from order where customer_id= ' 1 ';E, the advantages of using binding parameters:Why do we use binding named parameters? The existence of any one thing has its value, specific to the binding parameter
efficiency.② can prevent the generation of SQL injection security vulnerabilities:SQL injection is a special attack on SQL statements, such as for our common user login, in the login interface, the user input user name and password, the login validator may generate the following HQL statement:"From user user where use
) Session. Load (customer. Class, "1 ");Query query = session. createquery ("from order where order. Customer =: customer ");Query. setproperties ("customer", customer );List list = query. List ();The above code generates an SQL statement similar to the following:Select * from order where customer_id = '1 ';E. advantages of using bound parameters:Why do we need to bind a named parameter? The existence of any thing has its own value. Specifically, binding parameters has the following two main adv
, for common user logon, you can enter the user name and password on the logon interface, at this time, the login verification program may generate the following hql statement:
"From user where user. Name = '" + name + "' and user. Password = '" + password + "'"
This hql statement is logically correct, and the logon verification function is generally completed co
security vulnerabilities:SQL injection is a special attack on SQL statements, such as for our common user login, in the login interface, the user input user name and password, the login validator may generate the following HQL statement:"From user user where user.name= '" +name+ "' and user.password= '" +password+ "'"
security vulnerabilities:SQL injection is a special attack on SQL statements, such as for our common user login, in the login interface, the user input user name and password, the login validator may generate the following HQL statement:"From user user where user.name= '" +name+ "' and user.password= '" +password+ "'"
. For example, for common user logon, you can enter the user name and password on the logon interface, at this time, the login verification program may generate the following hql statement:"From user where user. Name = '" + name + "' and user. Password = '" + password + "'"This hql statement is logically correct, and the logon verification function is generally c
-4.2.1.final\project\etc\hibernate.properties.template Or Configurable property values in the Hibernate-release-4.2.1.final\project\etc\hibernate.properties file Iii. named parameters of HQLExample:/*** Use HQL according to the name Query method* @param entity*/public static void Query (String name) {Session s = null;try {S=hibernateutil.getsession ();HQL:The from behind is not the table name, but the object name (class name)String
First, use expression to generate query conditions using dynamic expressions,
Expression body = expression. Constant (true );
Body = expression. And (body, expression );
Then execute the query
Session. queryover
The following error is reported:
You cannot forcibly convert objects of the type "nhibloud. hql. Ast. hqlbitwiseand" to the type "nhibloud. hql. Ast. hqlbooleanexpression"
Solution:
Replace express
persisted classencapsulate each query result as an objectString sql= "Select U.name from User u";encapsulates each query result into an object arrayString sql= "Select u.name,u.id from User u";encapsulates each query result into an object through a constructor functionString sql= "Select New Login (U.name,u.passwoord) from User u";5, paging queryUniqueresult () method gets a unique objectPublic long Findcount (String
Query LanguageHibernate Query Language (HQL) is an object-oriented query language, similar to SQL, but not to operations on tables and columns, but object-oriented and their properties. HQL queries are translated into traditional SQL queries by Hibernate to manipulate the database.Although you can use local SQL statements directly, I recommend that you use the HQL
1. query all fields of the entire ing object
Java code
// The direct from query shows a ing object, that is, querying all fields of the entire ing object.
String hql = "from users ";
Query query = session. createquery (hql );
List
Users = query. List ();
For (users user: Users ){
System. Out. println (user. getname () + ":" + User. getpasswd () + ":" + User. GETID ());
}
Output result
In many cases, the Data Access Layer (DAO layer) that we are responsible for usually uses SQL statements or HQL statements, and sometimes error when we use the HQL statement stitching, usually because we use standard SQL statements to open object-oriented statements that are indeed hibernate Sessionfactory.getcurrentsession (). createquery (SQL);We should change to Sessionfactory.getcurrentsession (). creat
The three major frameworks of Java_Web: the foundation of Hibernate + HQL, java_webhql
12.1 HQL language basicsThe Hibernate Query Language is HQL (Hibernate Query Language). You can directly use the object class name and attributes. The HQL syntax is similar to SQL, and has SQL keywords such as select, from, order by,
Hibernate is equipped with a very powerful query language that looks like SQL. But instead of being fooled by the similarity in grammatical structures, HQL is very conscious of being designed as a fully object-oriented query that can understand concepts such as inheritance, polymorphism, and correlation.Basic rules
The HQL syntax is similar to SQL and is a statement from the select from structure.
Hibernate is equipped with a very powerful query language that looks like SQL. But instead of being fooled by the similarity in grammatical structures, HQL is very conscious of being designed as a fully object-oriented query that can understand concepts such as inheritance, polymorphism, and correlation.Basic rules
The HQL syntax is similar to SQL and is a statement from the select from structure.
Hql:hibernate Query Language.
Characteristics:
>> 1, similar to SQL, the syntax in SQL is basically straightforward to use.
>> 2,sql queries are columns in tables and tables, and HQL queries are objects and properties in objects.
>> 3,hql keywords are case-insensitive, and the class name and property name are case-sensitive.
>> 4,select can be omitted.
1, simple query, employee is entity name
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.