我有一个有趣的情况。我正在做一个游戏。我有一个带有2d对象'Space'的电路板。每个“空间”都有四个对象'边界'(北,东,南,西)的引用。
空间共享对“边界”的引用。例如,位置(0,0)处的“空间”与位置(1,0)处的“空间”的西边界共享其东边界。这允许我只在事情发生时更新边界(如果被破坏,从墙到无)。
任何想法如何使用Hibernate保持这样的东西?我真的有一对多的边界有很多空格,但我不知道如何将它们特定地与特定的边界(北,南,西,东)联系起来。我也不知道如何设置它以便两个'Space'对象共享对单边界对象的引用。
public class Space {
private Boundary northBoundry;
private Boundary eastBoundry;
private Boundary southBoundry;
private Boundary westBoundry;
//hero on the Space
private HeroBase hero;
private long spaceId;
//getters and setters
}
public class Boundary {
public static final String NONE = "none";
public static final String CLOSED_DOOR = "closed_door";
public static final String OPEN_DOOR = "open_door";
public static final String WALL = "wall";
private String type;
long boundaryId;
//getters and setters
}
答案 0 :(得分:0)
您所描述的是空间与每个边界之间的多对一关系:
public class Space {
@ManyToOne
@JoinColumn(name="NORTH_BOUNDARY")
private Boundary northBoundary;
@ManyToOne
@JoinColumn(name="EAST_BOUNDARY")
private Boundary eastBoundary;
@ManyToOne
@JoinColumn(name="SOUTH_BOUNDARY")
private Boundary southBoundary;
@ManyToOne
@JoinColumn(name="WEST_BOUNDARY")
private Boundary westBoundary;
}