hibernate 如何创建包含自身的EntityView?

7uhlpewt  于 2022-12-29  发布在  其他
关注(0)|答案(1)|浏览(84)

基本上我想这样做,但我只是找不到解决方案或关键字。

@EntityView(Location.class)
public interface LocationView {
    @IdMapping
    int getId();

    String getName();
    
    LocationView getParent();
}
lnxxn5zx

lnxxn5zx1#

不允许在视图中再次引用同一个视图,因为这种循环性使得实体视图必须变得可变,或者引入某种惰性代理。
考虑一下您希望如何将响应建模为JSON,实体视图Map将自然地遵循该模型,例如类似于以下内容:

@EntityView(Location.class)
public interface LocationIdView {
    @IdMapping
    int getId();
}
@EntityView(Location.class)
public interface LocationView extends LocationIdView {
    String getName();
    LocationIdView getParent();
}

@EntityView(Location.class)
public interface LocationIdView {
    @IdMapping
    int getId();
}
@EntityView(Location.class)
public interface LocationBaseView<T extends LocationIdView> extends LocationIdView {
    String getName();
    T getParent();
}
@EntityView(Location.class)
public interface LocationView extends LocationBaseView<CountryLocationView> {
}

@EntityView(Location.class)
public interface CountryLocationView extends LocationBaseView<ContinentLocationView> {
}

@EntityView(Location.class)
public interface ContinentLocationView extends LocationBaseView<LocationIdView> {
}

相关问题