Hello, I need to know how to save classes, mapping and persistence, which contains a list of it's own class (menu itens):
ItemClass{
List<ItemClass>item;
}
Item {Item,Item{Item,Item{Item,Item},Item}},Item
My actual main class for test->
Code:
public static void main(String[] args) {
MenuDao dao = new MenuDao(session);
for(int i=1;i<4;i++)
{
BotaoMenu b=new BotaoMenu();
b.setTexto("Botao"+i);
b.setLink("#");
List <BotaoMenu> botoes = new ArrayList <BotaoMenu>();
for(int j=1;j<4-i;j++)
{
botoes.add(new BotaoMenu("Teste","#"));
}
session.beginTransaction();
dao.salva(b);
session.getTransaction().commit();
}
}
Entity Class
Code:
@Entity
public class BotaoMenu {
@Id
@GeneratedValue
private long id;
@OneToMany(mappedBy="botaoPai")
private List<BotaoMenu> botoesMenu;
/*Saw it in internet but don't think it work in my case:*/
@ManyToOne(cascade={CascadeType.ALL})
@JoinColumn(name="manager_id")
private BotaoMenu botaoPai;
/* */
private String texto;
private String link;
public BotaoMenu()
{
}
public BotaoMenu(List<BotaoMenu> botoesMenu, String texto, String link){
this.botoesMenu=botoesMenu;
this.texto=texto;
this.link=link;
}
getters and setters..
}
This approach of using father instance (botaoPai) in variable I saw in one site, and I know I even did it in main menu, because in this way I don't know how I recover its as a List.