【问题标题】:Increment value in Postgresql when adding new entry, using jpa/hibernate Spring使用 jpa/hibernate Spring 添加新条目时在 Postgresql 中增加值
【发布时间】:2017-03-31 14:40:21
【问题描述】:

我有 2 个表,一个是制造商,一个是监视器,以便不应用 1+n 查询。我希望能够增加每个制造商下的显示器数量:

    manufacturer table:                      monitor
    id    name     totalMonitors             id     name     manufacturerId

    1     manuf1     100000                  1      mon1     1
    2     manuf2     2000                    2      mon2     2

实体:

public class Manufacturer{

    private long id;

    private String name;

    private long totalMonitors;
}

public class Monitor{

    private long id;

    private String name;

    private Manufacturer manufacturer;
}

我使用 DTO 处理数据。顺便说一句我真的很困惑 您可以在数据库中增加一个值,对于查询,我将使用 DAO 接口。

     @QUERY("Query to get the number of total monitors for each manuf")
     long countByManufacturerId(List<Manufacturer> manufacturers);

由于这将是一个 Web 应用程序,因此我无法计算每次数据库中的监视器数量 因为这会降低性能,我想知道是否有解决方案 每当添加/删除操作时触发值“totalMonitors”的增量 在 DB 上执行。

【问题讨论】:

    标签: java spring postgresql hibernate jpa


    【解决方案1】:

    Yuo 可以尝试查看 JPA 回调注释。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-24
      • 2016-06-26
      • 1970-01-01
      • 2012-01-30
      • 2021-03-11
      • 2018-06-02
      • 2016-10-02
      • 1970-01-01
      相关资源
      最近更新 更多