Probleme de mis a jour ManyToMany
Bonjour,
dans le cadre d'un développement Web sous Netbeans :
EJB / JSF / Facelets / Glassfish.
j'ai un problème de liaison entre 2 tables (ManyToMany):
t_bookmarks n<>n t_tags
Je me suis aidé de ce topic :
http://www.developpez.net/forums/sho...ght=ManyToMany
mon problème se produit lors d'un ajout d'un bookmark, j'entre un bookmark dans un formulaire, je valide par un bouton "add" et je me retrouve dans mon bean.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
public class BookmarksManagementBean
{
@EJB
private BookmarksFacadeLocal bookmarkFacade;
private long id; // Primary key
private String url;
protected Collection<Tags> tags;
public String addBookmark()
{
Bookmarks b = new Bookmarks();
Tags t = new Tags();
ArrayList al = new ArrayList();
// init new bookmark with forms
b.setUrl(url);
b.setTags(tags);
// init new tag with static data
t.setName("informatique");
al.add(t.getBmks());
t.setBmks(al);
al = null;
al = new ArrayList();
al.add(t);
tags = al;
b.setTags(tags);
// insert data in database (t_bookmarks and t_tags)
bookmarkFacade.create(b);
}
(...)
} |
mon bean utilise la session "bookmark" :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
@Stateless
public class BookmarksFacadeBean implements BookmarksFacadeLocal
{
@PersistenceContext
private EntityManager em;
public void create(Bookmarks bookmarks)
{
em.persist(bookmarks);
}
(...)
} |
et ma session utilise l'"entity class" suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
@Entity
@Table(name="t_bookmarks")
public class Bookmarks implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id; // Primary key
@Column(name = "url", unique = true, updatable = false, nullable = false, length = 256)
private String url;
@ManyToMany(cascade={CascadeType.PERSIST}, mappedBy="bmks")
protected Collection<Tags> tags;
(...)getter() and setter()(...)
} |
Entity class "Tags" :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
@Entity
@Table(name="t_tags")
public class Tags implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id; // Primary key
@Column(name = "name", unique = true, updatable = false, nullable = false, length = 64)
private String name;
@ManyToMany(cascade={CascadeType.PERSIST})
protected Collection<Bookmarks> bmks;
(...)getter() and setter()(...)
} |
En résumé:
- je n'ai aucun message d'erreur sous l'explorateur et sous les logs.
- l'insertion s'effectue normalement dans la table "t_bookmarks".
- la collection de tags s'ajoute normalement aussi dans la table "t_tags".
Le problème :
- L'INSERTION DANS MA TABLE JOINTURE "t_bookmarks_t_tags" NE S'EFFECTUE PAS !
Merci d'avance. :roll: