我想在GORM中定義一個樹結構。這裏是我的模型:GORM中的樹結構(grails)
class Tree {
String name
Level rootLevel
static hasOne = [rootLevel: Level]
static hasMany = [levels: Level]
static mappedBy = [levels:"parentTree"]
}
class Level {
String name
Tree parentTree
Level parentLevel
Set<Level> subLevels
static belongsTo = [parentTree: Tree]
static hasMany = [subLevels: Level]
}
插入似乎工作正常,但是當我無法加載一個具有許多級別和子級別的樹。 我想我錯過了關係中的某些東西: - 樹應該有一個對rootLevel的引用(並且可選地指向所有子元素) -a Level應該引用其父級別,其子級別和全局父樹
你能指出我得到一個像這樣的樹結構的正確方向嗎? 感謝
Hibernate不喜歡遞歸結構,但它是可能的。請解釋一下你的意思,但是當我無法加載多層次,多層次的樹時。你有錯誤還是什麼? – 2011-05-04 08:36:17
問題是級別填充了父級樹ID,但是當您加載樹時,Level級別出現以下錯誤「找到給定標識符的多行」。 – Wavyx 2011-05-04 09:25:27