[Follow hql]
In the previous article, with your help, we finally completed the cascade insert and save operations for the primary and child objects (corresponding to the insertion of the primary and child tables ). Continue to explore the query system provided by nhib.pdf from now on!
Nhib.pdf provides a special query language hql (Hibernate query language). If it is only from the query perspective, nhib.pdf translates hql into a SQL translator!
Let me write an hql statement!
The requirement is described as follows: Data. universityclass is the ing Class Name.
Name of the database table corresponding to the universityclass
Startdate is an attribute of data. universityclass. Of course, it also corresponds to a field in the database table!
Now I only want to get the value of a startdate attribute, rather than the default select *.
After reading the instructions, this is too simple and you may write it out immediately.
Select startdate from data. universityclass
Or, if you think the class name cannot be precisely located, give the following answer:
Select data. universityclass. startdate from data. universityclass
In fact, both of them are wrong. I tested it for 10 minutes before I understood it!
Error: Undefined alias or unknown mapping: startdate [select startdate from data. universityclass]
Later, I took a very careful look at other examples. The correct syntax is as follows:
Select myclass. startdate from data. universityclass as myclass
The results are displayed correctly. Why?
[Simple thinking]
From an object-oriented perspective, we can find that this also contains some oo ideas,
Let's take a closer look at what data. universityclass is. That's right, class name!
Can the class name attributes be directly used? No, unless the class is static,
So is as myclass very similar to setting up a class object? The rest is right!
Note the wording, including tables, fields and classes, attributes, and objects!