![]() |
1
1
定义关系What you're defining is a unidirectional one-to-many, with the parent being the 'owner' of the relationship. If you define it like this:
然后你可以这样做:
或者我相信你也可以这样速记:
通过定义与
To make it easier to work with, you could also make the relationship bidirectional by adding the following property:
如果你使用动态
正在检索所有后代你在这里有一些选择,但我不认为有一种内置的方式可以自动完成。 一种选择是编写自己的递归或迭代方法,来获取和收集所有子级。可以找到一个这样的例子 here . Alternatively, if you execute this method a lot and it become a bottleneck, you could do some manual manipulation of your database. You might have triggers that operate on inserts and updates in your RoleType table that maintain lists of implicit relationships between all RoleTypes.
例如,如果创建
|
![]() |
Gero Mendy · 如何为一个类分配兵变的结果。查询 1 年前 |
![]() |
Hamvy B · 替换不推荐的hibernate方法 1 年前 |
![]() |
Martin Pfeffer · Spring Boot JPA 1 年前 |
|
denstran · 休眠未生成正确的id 1 年前 |
![]() |
Frank · 忽略/跳过Hibernate架构验证中的特定字段 1 年前 |