使用 Hibernate 将列作为列总和或差值

发布于 2025-01-03 07:07:14 字数 263 浏览 3 评论 0原文

我有一个 hibernate pojo 类,它有一些字段。假设有三个字段。一个是其他的总和。我的意思是有第 1 列、第 2 列、第 3 列。

我如何使用 Hibernate 作为注释来定义第 3 列 =column1+column2 。 我想我们可以用标准 SQL 来定义它,比如

create table x(columnt1 ......,column2......,column3 as column1+column2)

我不确定,有没有办法做到这一点冬眠?

I have a hibernate pojo class and it has some field. Assume that there are three field. One is sum of the others. I means there are column 1, column 2 , column 3.

How can i define column 3 =column1+column2 with Hibernate as annotation.
I guess we can define it with standart SQL like

create table x( columnt1 ......, column2 ......, column3 as column1+column2)

i'm not sure , is there a way to do that with hibernate ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无畏 2025-01-10 07:07:14

省略该列并使用属性

public int getProperty3()
{
    return getProperty1() + getProperty2();
}

leave out the column and use properties

public int getProperty3()
{
    return getProperty1() + getProperty2();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文