-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 (
//need to ensure that the setter and getter in the EMP and empproperties as well as attributes and parameter placeholders (: ename) are consistent//Dynamic Query@Test Public voidtest4 () {empproperties EP=Newempproperties (); //set Query conditionsEp.setename ("%a%"); Ep.setstartdate (NewDate (383155200000L)); Ep.setenddate (NewDate ()); Ep.setjob ("Clerk"); //1.obtain org.hibernate.Session object.Session ss=hibernateutil.getsession (); //2.hql statem
There are many ways to query hql, and yesterday came into contact with a query method based on the Pojo class, summarized here:
Usually we can use simple "from [POJO OBJ]" syntax to assemble a simple hql query. If we want to specify a field, we can use the syntax of the new Pojo object, as follows:
The following article uses Weiboaccountbean to refer to Pojo obj
The 1.map uses Var hql=string. Format (@ "Select New Map (TC. Limitindextype as LIMITINDEXTYPE,TC. Limitscope as LIMITSCOPE,TB. ID as ID) from Baslimitconfig tb,basproductgroup ta, Baslimittype TC where TB. Limitdim1id =ta. Id and TB. LIMITDIM2ID = TC. Id ");//This is the package of my framework is actually the session. Createqueryvar List2 = dao.findlist Nhibernate HQL Anonymous
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
object [] array. However, because there are no repeated elements in the Set, the values of username and password cannot be the same. Change hql to string hql = "select new set (name, passwd) from users ";
7. Modify the default query result (query. List (). The result is not returned in the form of an object [] array and is returned in a custom type.
Custom class
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
) 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, bind
associates the named parameter with a persistent object, as shown in the following code:
Customer customer = (customer) 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 usin
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
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.
() method, which associates the named parameter with a persistent object, as shown in the following code:Customer customer = (customer) 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. advantag
persistent class. The class name is String hql = "from Student"; // String hql = "from Student where sname = 'zhangsan '"; // 3. create a Query object Query = session. createQuery (hql); // 4. the query result is a list set List Iii. Simplest Query
Query all information
Fro
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.
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
I. Introduction of HQLHQL (Hibernate query Language) is an object-oriented query language that relies on the query class, each of which corresponds to a querying object. The query steps are as follows:1) Get Hibernate Session Object2) Writing HQL statements3) Call the session's CreateQuery () method to create a query condition with the HQL statement as the argume
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.