Using the HQL statement to complete the insert operation is not possible, whether you use the Insert Into....values ... or insert Into.....select ..... No,
because Hibernate's HQL language is used for object-oriented query functionality, but there is no query action involved in the insert operation, so HQL cannot be used for INSERT statements, while Select, Upda
The parameters passed through queryMap of valuelist are of the string type by default. In hql of the valuelist configuration file, an error is returned if this value is directly assigned to an integer field. We generally use transformation functions in hql for processing, as shown below:Copy codeThe Code is as follows:From com. berheley. hcms. persistence. model. TBaseAreas as tbWhere tb. status = '1'/~ HId
Hql Query methodThis is one of my most used and favorite, because it is flexible and intuitive to write, and not much worse than the syntax of the familiar SQL. Conditional query, paged query, connection query, nested query, write up and SQL syntax basically consistent, the only difference is to replace the table name with the class or object. Other, including some query functions (count (), sum (), etc.), query conditions, and so on, all the same as
The method of "from XXX where XXX" is used, of course, to query the entire record and encapsulate it into the corresponding bean.
However, in many cases, you do not need to retrieve all the field values, especially when there are BLOB and CLOB fields. encapsulation of unwanted content will cause a huge waste of memory.
In this case, you can use the new HQL operation.
For example:
Select new PerformanceValue (P. id, P. regionNo, P. regionName, P. rep
:
from Person where name.first = 'Gavin' and name.initial = 'A' and name.last = 'King')
There are two good reasons why you should not think of it as this: first, it is not entirely applicable to various database platforms; second, queries are now dependent on the order of attributes in the ing file.12. HQL example
Hibernate queries can be very powerful and complex. In fact, a major selling point of Hibernate is the power of query statements. Here are
Hql query language basics .....
1. From
1.1 Single Table query
From eg. CAT as Cat. In this example, cat is just an alias. It is easy to write with other substatements.
1.2 multi-table queries
From eg. Cat, eg. DogFrom eg. CAT as Cat, eg. Dog as dog2 Join Problems(Inner) joinLeft (outer) joinRight (outer) joinFull joinHql also supports these features in SQLThe following is a small topic. I have never used any of the above features. Now, I wantLet's ta
Delete methodGetSession (). Delete (arg0);Write this DELETE statement today using this delete () This method, according to the ID to delete records, HQL and ordinary SQL is still different,Normal SQL Package the Delete () method is to directly pass a condition in, and HQL is not the same, he is to operateThe entire entity class passes in, if but wears an ID to go in, the program is not to run up.Public Test
Detailed concept on PPT:1.HQL(1) Query interface
Object Uniqueresult (), which returns a unique instance of the match condition, or null if none.
2.QBC (Criteria interface, criterion interface, expression class (1) Create in session
Criteria Createcriteria (class Class) Persistence class name
(2) Criteria interface
Object Uniqueresult ()
List List ()
Criterion Add (Criterion Criterion) adds some restrictions to query result
From is the simplest hql statement and the most basic hql statement. The from keyword is followed by the class name of the persistence class. For example:From personAll instances are selected from the person persistence class. In most cases, we recommend that you create an alias for each instance of this person. For example:From person as PHere, the alias of an instance in the person persistence class is P.
Mysql paging SQL statement: select * from table limit start index, Query Count; e.g. select * from table limit; queries the 10 statements starting from 0 in the table (mysql index starts from 0). hibernate has a very hql statement paging:
Query query = session. createQuery (hql); query. setParameter (0, userId); query. setMaxResults (maxCount); query. setFirstResult (firstResult); return query. list ();
Q
Hibernate Query Language HQL and advanced queryDevelopment of database operation implementation classImport Java.util.list;import org.hibernate.query;import Org.hibernate.sqlquery;import Org.hibernate.Session;import Org.hibernate.transaction;import Org.sf.dao.idepartmentdao;import Org.sf.entity.department;import Org.sf.util.HibernateSessionFactory;public class Departmentdaoimpl implements Idepartmentdao {/** * Get all the Faculties information collect
HQL: Fully Object-oriented queryexecution order of SQL :1. from2.Where to filter the underlying data The difference between where and having : 1. different order 2.where filtering underlying data 3. filtering aggregate functions3.Group by4.Select5. Having6.Order byUse Hibernate Query , use One of Hibernate interface queryHQL is an object-oriented query statement , so it is followed by the class nameQuery query = Session.createquery ("Select Id,name
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 Class (strictly speaking t
One, find (String queryString);Example: This.gethibernatetemplate (). Find ("From Bean". User ");Returns all user objectsTwo, find (String queryString, Object value);Example: This.gethibernatetemplate (). Find ("From Bean". User u where u.name=? "," Test ");or fuzzy query: This.gethibernatetemplate (). Find ("From Bean". User u where u.name like? ","%test% ");Returns an object with the Name property value of test (fuzzy query that returns the object with the Name property value containing test)T
HQL in keyword query reported "Ljava.lang.Long; Cannot is cast to Java.lang.Long "exception.Incoming parametersLong[] Type: useridsLong type: RIDQuery q = getsession (). CreateQuery ("Select User from user user join User.roles as role where role.id Q.setparameter ("RID", RID);q.setparameter ("UIDs", UIDs);The error message for executing this code is as follows:650) this.width=650; "class=" Magplus "title=" click to view original size picture "src=" ht
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.