【发布时间】:2015-01-11 19:13:08
【问题描述】:
我有一个带有主键的实体,例如下面的“id”。随着该实体的发展,我有另一列将围绕该组的第一个“id”对该实体进行分组。
简而言之,如果“idstore”为空,则第二列“idstore”应插入“id”值,否则插入“idstore”值。我怎样才能用 Hibernate 实现这一点?我正在使用休眠 4.0.1
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Integer id;
@Column(nullable=flase)
Integer idstore;
这个想法是在 db 中有一个类似的情况(假设两个组的 id 为 1 和 3)
+----+---------+
| id | idstore |
+----+---------+
| 1 | 1 |
+----+---------+
| 2 | 1 |
+----+---------+
| 3 | 3 |
+----+---------+
| 4 | 1 |
+----+---------+
| 5 | 3 |
+----+---------+
由于没有答案,我不知道如何使用 JPA 处理这个问题,所以我在数据库上添加了一个触发器来完成这项工作。不漂亮,但只有快速出路。
【问题讨论】:
标签: hibernate postgresql jpa