-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Recursive List of Objects, mapping and persistence.
PostPosted: Mon Jan 06, 2014 2:05 pm 
Newbie

Joined: Mon Jan 06, 2014 2:00 pm
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.