There can only be a single entity named in the from-clause; it can optionally be aliased. If the entity name is aliased, then any property references must be qualified using that alias; if the entity name is not aliased, then it is illegal for any property references to be qualified. No joins either implicit or explicit can be specified in a bulk HQL query. Sub-queries may be used in the where-clause; the sub-queries, themselves, may contain joins. ExecuteUpdate method:. However, you can force NHibernate to properly reset the version or timestamp property values through the use of a versioned update.
Note that custom version types NHibernate. IUserVersionType are not allowed in conjunction with a update versioned statement. The int value returned by the IQuery.
ExecuteUpdate method indicate the number of entities effected by the operation. Consider this may or may not correlate to the number of rows effected in the database. An HQL bulk operation might result in multiple actual SQL statements being executed, for joined-subclass, for example. The returned number indicates the number of actual entities affected by the statement.
Going back to the example of joined-subclass, a delete against one of the subclasses may actually result in deletes against not just the table to which that subclass is mapped, but also the "root" table and potentially joined-subclass tables further down the inheritance hierarchy. Superclass properties are not allowed; and subclass properties do not make sense. Currently, this is checked during query compilation rather than allowing the check to relegate to the database.
Note however that this might cause problems between NHibernate Type s which are equivalent as opposed to equal.
This might cause issues with mismatches between a property defined as a NHibernate. DateType and a property defined as a NHibernate. TimestampType , even though the database might not make a distinction or might be able to handle the conversion. By calling the executeUpdate method on query object, we can fire the HQL non-select commands. The executeUpdate method returns the rows count. By using the count, we can come to know that, how many records are updated in the database.
For all non-select operations insert,update and delete , it is mandatory to begin and commit the transaction. HQL delete query is as same as the update. Foo and foo. This manual uses lowercase HQL keywords. Some users find queries with uppercase keywords more readable, but we find this convention ugly when embedded in C code.
Most of the time, you will need to assign an alias , since you will want to refer to the Cat in other parts of the query. This query assigns the alias cat to Cat instances, so we could use that alias later in the query. The as keyword is optional; we could also write:. It is considered good practice to name query aliases using an initial lowercase, consistent with naming standards for local variables eg. We may also assign aliases to associated entities, or even to elements of a collection of values, using a join.
The inner join , left outer join and right outer join constructs may be abbreviated. In addition, a "fetch" join allows associations or collections of values to be initialized along with their parent objects, using a single select. This is particularly useful in the case of a collection. It effectively overrides the outer join and lazy declarations of the mapping file for associations and collections.
See Section The associated objects are not returned directly in the query results. Instead, they may be accessed via the parent object.
It is possible to create a cartesian product by join fetching more than one collection in a query, so take care in this case. Join fetching multiple collection roles is also disabled for bag mappings. Note also that the fetch construct may not be used in queries called using Enumerable. Finally, note that full join fetch and right join fetch are not meaningful. The select clause picks which objects and properties to return in the query result set.
The query will select Mate s of other Cat s. Actually, you may express this query more compactly as:. You may even select collection elements, using the special elements function.
The following query returns all kittens of any cat. Queries may return properties of any value type including properties of component type:. Collections may also appear inside aggregate functions in the select clause. The distinct and all keywords may be used and have the same semantics as in SQL. NHibernate queries may name any. NET class or interface in the from clause. The query will return instances of all persistent classes that extend that class or implement the interface.
The following query would return all persistent objects:. The interface INamed might be implemented by various persistent classes:. This means that the order by clause does not correctly order the whole result set. In order to use non-mapped base classes or interfaces in HQL queries, they have to be imported. See Section 5. The where clause allows you to narrow the list of instances returned.
0コメント