我想在获取时在hibernate映射文件中添加一个(where)条件,
我该怎么做,例如 fetch="select"where id != 1
,我也不使用注释,所以请在映射 (hbm) 文件中指定。
最佳答案
根据 Hibernate 文档,您可以指定 where
映射集合时的子句:
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.
<class>
也支持此功能水平。
关于java - 如何在 hibernate 映射文件中创建子句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3281831/