![]() |
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.
例如,如果创建
|
![]() |
AntonBoarf · 休眠/春天:悲观主义者vs乐观主义者锁定? 7 年前 |
![]() |
Sinan Samet · Hibernate给出无法确定类型错误 7 年前 |
|
Carlos Chávez · Tomcat/Hibernate配置 7 年前 |
![]() |
Seric · 更改Naturald参数名称后出错 7 年前 |
![]() |
OOvic · 使用JoinTable实现多个关系中的JPQL查询 7 年前 |
![]() |
Jovan0042 · 在H2中持久化多个实体引发异常 7 年前 |