java - 如何在 hibernate 映射文件中创建子句?

标签 java hibernate

我想在获取时在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/

相关文章:

java - 如何在java中使用for循环动态创建二维数组?

java - EntityManager 使用 id 以外的特定列合并

java - 推土机将非通用集合映射到属性

java - 如何将变量传递给 Pepper-Box 纯文本配置

java - hibernate中一对多关系映射错误

java - JPA 惰性设计建议

java - Spring Boot 2.x.x 与 hibernate 4.3.x 的兼容性问题

java - 使用 shell 脚本在远程计算机上执行多个命令

java - 构造仅接受数字的 vaadin 14 Textfield

java - java xml 解析器编码时出错