For example, for the Tuser class
1. Object Query
String hql = "from Tuser ";
Executing this statement will return records of Tuser and Tuser sub-classes.
Note: If the Tuser class has a foreign key, an error is returned during the query!
Solution: Select alias. Attribute from class as alias. No alias. Attribute still reports error!
Hql = "from Java. Lang. Object"
Records of all database tables in the databas
HQL Sentence Learning:(1) Preliminary understanding of HQL① HQL is the object-oriented query language, which uses the class name and the property name when querying,and theSql query uses the table name and the field name .② Case Sensitive③ Package Name: If the class name is not duplicated, do not write the package name, if the different packages have the same cla
Recently has been using SPRING-DATA-JPA this thing, feel the method of annotation HQL statement is a very common method,There are some experiences on HQL to share:I. Join of the HQLThe advantage of HQL is the direct correlation, but there are some places to be aware of when a join query is made through HQL statements:H
Hql instance:
1.Query all records in the Table: from category
2.Conditional query with WHERE clause: from Category C where c. Name> 'c5'
3.The result is sorted by a certain field: from Category C order by C. Name DESC (DESC indicates descending order, ASC indicates Ascending Order)
4.Remove duplicate records to obtain a single record: Select distinct C from Category C order by C. Name DESC
5.Query with parameters: from Category C where c. ID
Hql: hibernate qusery language. If you are familiar with it, you will find that it is very similar to SQL. However, you should not be confused by the illusion that hql is object-oriented (OO, looking at every object with a life perspective, they are so vivid ). If you have some knowledge about Java and SQL statements, hql is easy for you. You can take full advant
?) **)String hql = "from user where username =?";list Focus : HQL uses entity query technology, such as the following example: String hql= "from user User"; List list=session. CreateQuery (HQL). List (); The result of the above code execution is to query out all the data corresponding to the user entity object , and e
Hibernate Query Language HQL
Keywords are case-insensitive in hql, but property and class names are case-sensitive
1, simple attribute query "important"* A single property query that returns a list of result set properties consistent with the corresponding attribute types in the entity class and the element type* Multiple attribute queries, the returned collection element is an object array, the type of the
Tags: blank LAN purpose based on add now programming language Hibernate modeSQL: Full-Name Structured Query Language (structured Query Language), a special purpose programming language, is a database query and programming language for accessing data and querying, updating and managing relational database systems , and is also the extension of the database script file.HQL: HQL (Hibernate query Language) queries provide richer and more flexible query ch
HQL multi-table joint query problem HQL multi-Table query only needs to query the expected objects when fromAAAasa, BBBasbwherea. AB. a. When the two objects are retrieved, HQL can write selectafromAAAasa and BBBasbwherea to retrieve only one object. AB. a
HQL multi-table joint query problem
HQL (Hibernate Query Language) Object-oriented query language, unlike SQL, the object names in HQL are case-sensitive (except for Java classes and other parts of the property are not case-sensitive); HQL is the object, not the table, and the polymorphism is supported; HQL is mainly operated by query. How query is creat
A recent business need is to calculate the order creation time is now more than 4 hours of orders are found out! Then we need to use the DATE function. I got a look on the net. The total date function has a few:
Current_date ()
Returns the current date of the database
Time function
JPAQL HQL
Current_date ()
Returns the current date of the database
Current_time ()
Time
Time function
JP
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. Generally, we use transformation functions in hql for processing. The code for copying the code is as follows: entrykeyareasinfoadapterbeanparent?acthibe
The parameters passed through queryMap of valuel
Join usage, hql method, fetch in hibernate
The following text is taken from join, join2, hql, fetch.
Join usage:
Inner join and outer join:
The most common (inner by default ):
Select
The main spirit of inner join is exclusive. Call it exclusive! That is, materials that do not match the join rule will be excluded. For example, the supplier code of a product (supplierid) in the product is not displayed in
* First query to this object, and then delete the object */ @Test public void testdelete () { = session.begintransaction (); = (userentity) session.load (userentity. Class,3); Session.delete (user); Transaction.commit (); }7: Basic HQL QueryGet a single object/** * Get a single object */ @Test public void testhql () { String hql = "fro
To implement a slightly more complex query in the ActiveRecord, we cannot use the Find (ID), findall () two static methods, then we need to use the HQL statement to implement, In the usual use of castle I think we all notice under the Activerecordbase class, because only provide find (ID), findall () such as two static query methods, these two methods in our query is not enough, Still cannot solve some complex queries in the actual development, this a
//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
Use hql to query databases:Perform the following steps:
1. Obtain the query object
//1获取query对象 String hql="FROM Employee e where e.salary>?"; Query query=session.createQuery(hql);
2. Bind a parameter (you can bind a location parameter or a name parameter (but it must start with:) or an object parameter)
Location parameters:
//2绑定
I have long known that myeclipse provides a hql editor for hibernate, which has been used before. However, when I used it today, I suddenly couldn't remember it. I found it for half a day, in my opinion, the control mode adopted by eclispe makes the user interfaces of many tools inconsistent, resulting in the user's inhabits when using a certain control.
Location of the myeclipse hql Editor:
Right-cl
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.