1

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` varchar(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;

}
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.