【问题标题】:How to define transient property in hibernate?如何在休眠中定义瞬态属性?
【发布时间】:2011-10-07 04:24:22
【问题描述】:

我使用单独的 hbm.xml 文件进行休眠映射,并在定义瞬态属性时遇到问题。我花了几个小时没有运气来搜索工作示例或编写自己的示例。
有人可以帮助我通过 hbm.xml (如果可能的话)使属性瞬态,因为它会使我的应用程序保持一致。如果通过 hbm.xml 无法实现,那么尽管使用 xml 进行了注释。 欢迎任何指向现有文档或主题的链接。

我的示例映射类是:

<class name="Test">
    <id name="a" type="long">
        <generator class="identity" />
    </id>
    <property name="b" type="string" />
    <property name="c" type="string" />
</class>

示例实体类是:

public class Test {
    private Long a;
    private String b;
    private String c;

    public void setA(Long a) { this.a = a; }
    public Long getA() { return a; }

    public void setB(String b) { this.b = b; }
    public String getB() { return b; }

    public void setC(String c) { this.c = c; }
    public String getC() { return c; }
}

【问题讨论】:

    标签: hibernate


    【解决方案1】:

    “通过 hbm.xml 使属性瞬态”?你的意思是有一个属性没有映射到数据库?只是不要映射它。

    【讨论】:

    • 哇!我比我想象的要愚蠢得多。无论如何,谢谢你帮助我。
    • 我一直在寻找解决方案。
    猜你喜欢
    • 2013-12-07
    • 2011-12-07
    • 1970-01-01
    • 1970-01-01
    • 2019-12-02
    • 1970-01-01
    • 1970-01-01
    • 2021-03-03
    • 1970-01-01
    相关资源
    最近更新 更多