Reputation: 2034
I want to add a (where) condition in hibernate mapping file when fetching,
how could i do that for example fetch="select" where id != 1
,am not using annotations also, so please specify within the mapping (hbm) files.
Upvotes: 2
Views: 4133
Reputation: 570575
According to the Hibernate documentation, you can specify a where
clause when mapping a collection:
6.2. Collection mappings
(...) The
<map>
element is representative:<map name="propertyName" (1) table="table_name" (2) schema="schema_name" (3) lazy="true|extra|false" (4) inverse="true|false" (5) cascade="all|none|save-update|delete|all-delete-orphan|delet(6)e-orphan" sort="unsorted|natural|comparatorClass" (7) order-by="column_name asc|desc" (8) where="arbitrary sql where condition" (9) fetch="join|select|subselect" (10) batch-size="N" (11) access="field|property|ClassName" (12) optimistic-lock="true|false" (13) mutable="true|false" (14) node="element-name|." embed-xml="true|false" > <key .... /> <map-key .... /> <element .... /> </map>
(...)
(9)
where
(optional): specifies an arbitrary SQL WHERE condition that is used when retrieving or removing the collection. This is useful if the collection needs to contain only a subset of the available data.
This is also supported at the <class>
level.
Upvotes: 1