Scenario Overview:I encountered such a problem in development:System and User relations: A user can belong to multiple systems, a system can have multiple users
Data structure: syssystem-system table, representing different system sysuser-user table, representing the user, attribute systems describes the Many-to-many relationship sys_user_system-relational table (not embodied as entity Class)
when the business logic is: Query a system under the user name contains "xbz" user, his
In the HQL statement, you cannot use limit to limit the number of bars that are displayed.
For example:
From User_info ORDER BY createdtime desc LIMIT 1
The number shown is not 1, but the number of bars you have queried, so the above notation is wrong.
How to solve the limit in HQL can not be used, and set the number of queries out of the collection, we should use the Setmaxresults (e) method to solve
.*;import org.hibernate.*;import org.hibernate.cfg.*;p ublic class Test {public static void main (string[ ] args) {//Here is the so-called establishment transaction session Session=new Configuration (). Configure (). Buildsessionfactory (). Opensession (); Transaction transaction=session.begintransaction (); TestTable testtable=new testtable (); listThe central idea of the entire file is to use the HQL statement to convert the query resu
Label:Question: How do I use MySQL functions in hibernate? 1.hibernate supports the original SQL statement query, using Session.createsqlquery () to create query objects; 2. How do I use the MySQL function in hql? You need to redefine Hibernate's dialect (dialect) to register your needs; The concept of a dialect (dialect) is mentioned here: Hibernate is still using SQL statements to perform database operations, although all relational databases supp
JPQL is an object-oriented query language, so it can fully understand the characteristics of inheritance, polymorphism, and correlation. And JPQL has built-in a lot of functions, greatly facilitates the function of JPQL query. Of course JPQL is still SQL-based, but the JPQL-to-SQL conversion does not need to be a developer's concern, and the JPQL parser is responsible for completing this transformation, and is responsible for executing the SQL statement to update the database.SQL is a query lang
Tags: blog code int get HTTP stringPaip. Methods for taking the day's records SQL and HQL hibernate#------of two ways ... function method and Date calculation method:Function method: DATEDIFF (D,createtime,getdate ()) =0//d specified as DayHB also has the same function:Date calculation method: Where createtime>= ' 2014-5-4 00:00:01 ' and createtimewhere createtime= ' 2014-5-4 00:00:00 'The date calculation should be used preferentially, because this m
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
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.