开发者

hibernate annotations same class reference

I'm in need of help with hibernate annotation, when I have a table with same parent id.

Like this example

CREATE TABLE `server` (
  `server` int(11) DEFAULT NULL,
  `name` va开发者_开发技巧rchar(20) DEFAULT NULL,
  `parentid` int(11) DEFAULT NULL,
  KEY `parentid` (`parentid`),
  KEY `server` (`server`),
  CONSTRAINT `server_fk` FOREIGN KEY (`parentid`) REFERENCES `server` (`server`)
);

Output like this

Server A
    Server B
        Server C
        Server D
    Server E
        Server C
        Server D
    Server F
    Server G

How can I map this in my Class

@Entity
public class Server {
    @Id @GeneratedValue
    private Long id;

    private String name, description;

    private Server parentid;

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜