Auto relacionamento com ManyToMany

0 respostas
javahibernate
R

Pessoal, estou com um problema pra fazer o Auto-relacionamento em uma ManyToMany.
Minhas entidades estão da seguinte forma:

Noticia:

@ManyToMany

@JoinTable(name = not_tag, joinColumns = @JoinColumn(name = not_id), inverseJoinColumns = @JoinColumn(name = tag_id))

private List tags;

Tag:

@ManyToMany(mappedBy=“tags”)
private List noticias;

JSP:

<c:forEach items="${tags}" var=“tag”>

${tag.nome}


</c:forEach>

Controller:

@RequestMapping(value = /cadastro, method = RequestMethod.POST)

private String adicionar(@ModelAttribute(noticia) @Valid Noticia novaNoticia, BindingResult result, Model model, MultipartFile imagem){

if (result.hasErrors()) {

return noticia.cadastro.tiles;

}

Authentication auth = SecurityContextHolder.getContext().getAuthentication();

String nomeUsuario = auth.getName();

Usuario usuario = repositorioUsuario.findByUsername(nomeUsuario);
Date data = new Date();
novaNoticia.setData(data);
    novaNoticia.setUsuario(usuario);
repositorioNoticia.save(novaNoticia);
return "redirect:/noticias/";

Como eu vou passar a lista de Tags escolhidas na tela para a noticia?

Criado 15 de janeiro de 2017
Respostas 0
Participantes 1