IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JPA Java Discussion :

EJB Entity Bean et problème de mapping


Sujet :

JPA Java

  1. #1
    Membre régulier
    Inscrit en
    Février 2008
    Messages
    222
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 222
    Points : 120
    Points
    120
    Par défaut EJB Entity Bean et problème de mapping
    Salut,

    J'ai une application web qui permet d'ajouter des documents dans une base de données, donc le nom, la date de création, l'emplacement, et une liste de modification. Je travail avec les EJB3, JBoss et postgresql.
    Tout d'abord, j'ai créé une classe document qui représente la table document dans la base de données, dont voici le code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    @Entity
    public class Document implements Serializable{
    	// les variables correspondent aux colonnes de la table Document de la base de données
    	@Column(name = "nom", nullable = false)
    	private String nom; // le nom du document
    	@Column(name = "date_creation", nullable = false)
    	private java.util.Date date_creation; // la date de création du document
    	@Column(name = "emplacement", nullable = false)
    	private String emplacement; // l'emplacement du document
    	@Column(name = "modification", nullable = false)
    	private java.util.Set<Modification> modification; // la date de dernière modification
    	@Column(name = "tag", nullable = false)
    	private java.util.Set<Tag> tag; // la liste des tags représentant ce document
    	private static final long serialVersionUID = -728268157L; 
    	private Long id; // l'identifiant obligatoire pour la table
    	@Column(name = "typeDocument", nullable = false)
    	private TypeDocument typeDocument; // le type du document : ex technique, commercial ..
     
     
    	// le constructeur qui est vide
     
    	public Document() {
    		super();
    	}
     
     
    	// redéfinition de la méthode ToString
     
    	public String toString() {
    		return "Document" + " nom=" + nom + " date_creation=" + date_creation
    				+ " emplacement=" + emplacement + " id=" + id;
    	}
     
     
    	// les getters et setters
     
    	public String getNom() {
    		return this.nom;
    	}
     
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
     
    	public java.util.Date getDate_creation() {
    		return this.date_creation;
    	}
     
     
    	public void setDate_creation(java.util.Date date_creation) {
    		this.date_creation = date_creation;
    	}
     
     
    	public String getEmplacement() {
    		return this.emplacement;
    	}
     
     
    	public void setEmplacement(String emplacement) {
    		this.emplacement = emplacement;
    	}
     
    	@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "document")
    	public Collection<Modification> getModification() {
    		if (modification == null) {
    			modification = new java.util.HashSet<Modification>();
    		}
    		return modification;
    	}
     
     
    	public void setModification(java.util.Set<Modification> modification) {
    		this.modification = modification;
    	}
     
     
    	public void addModification(Modification Modification) {
    		getModification().add(Modification);
    	}
     
     
    	public void removeModification(Modification Modification) {
    		getModification().remove(Modification);
    	}
     
     
     
     
    	@ManyToMany(cascade=CascadeType.ALL, mappedBy="document", targetEntity=Tag.class)
    	public java.util.Set<Tag> getTag() {
    		if (tag == null) {
    			tag = new java.util.HashSet<Tag>();
    		}
    		return tag;
    	}
     
     
    	public void setTag(java.util.Set<Tag> tag) {
    		this.tag = tag;
    	}
     
     
    	public void addTag(Tag tag) {
    		getTag().add(tag);
    	}
     
     
    	public void removeTag(Tag tag) {
    		getTag().remove(tag);
    	}
     
    	@Id // tag définissant la clé primaire
    	@GeneratedValue(strategy=GenerationType.AUTO) // tag indiquant que la clé est auto générée
    	public Long getId() {
    		return this.id;
    	}
     
     
    	public void setId(Long id) {
    		this.id = id;
    	}
     
    	@ManyToOne
    	@JoinColumn(name = "typeDocumentID")
    	public TypeDocument getTypeDocument() {
    		return this.typeDocument;
    	}
     
     
    	public void setTypeDocument(TypeDocument typeDocument) {
    		this.typeDocument = typeDocument;
    	}
     
     
     
    }
    Vous pouvez voir en rouge qu'il y a la liste de modification donc il y a une ralation OneToMany

    Voici maintenant le code de la classe modification :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    @Entity
    public class Modification implements Serializable {
    	// les variables correspondent aux colonnes de la table Modification de la base de données
    	@Column(name = "date", nullable = false)
    	private java.util.Date date; // la date de modification
    	@Column(name = "commentaire", nullable = false)
    	private String commentaire; // le commentaire pour expliqué ce qu'il a été fait comme modification
    	@Column(name = "documentID", nullable = false)
    	private Document document; // représente le document qui a été modifié
    	private Utilisateur user; // représente le user qui a fait cette modification
    	private static final long serialVersionUID = 258313988L;
    	private Long id; // identifiant obligatoire pour la table
     
    	// redéfinition de la méthode toString
     
    	public String toString() {
    		return "Modification" + " date=" + date + " commentaire=" + commentaire
    				+ " id=" + id;
    	}
     
    	// le constructeur vide
     
    	public Modification() {
    		super();
    	}
     
    	// les getters et les setters
     
    	public java.util.Date getDate() {
    		return this.date;
    	}
     
     
    	public void setDate(java.util.Date date) {
    		this.date = date;
    	}
     
     
    	public String getCommentaire() {
    		return this.commentaire;
    	}
     
     
    	public void setCommentaire(String commentaire) {
    		this.commentaire = commentaire;
    	}
     
    	//@ManyToOne(optional=false)
    	@ManyToOne
    	@JoinColumn(name = "documentID")
    	public Document getDocument() {
    		return this.document;
    	}
     
     
    	public void setDocument(Document document) {
    		this.document = document;
    	}
     
    	@ManyToOne
    	@JoinColumn(name = "UserID")
    	public Utilisateur getUser() {
    		return this.user;
    	}
     
     
    	public void setUser(Utilisateur user) {
    		this.user = user;
    	}
     
    	@Id // tag définissant la clé primaire
    	@GeneratedValue(strategy=GenerationType.AUTO) // tag indiquant que la clé est auto générée
    	public Long getId() {
    		return this.id;
    	}
     
     
    	public void setId(Long id) {
    		this.id = id;
    	}
     
    }

    Maintenat, côté servlet je veux ajouter un nouveau document, donc dans le code je cré un document et j'appel la méthode qui se trouve dans mon session bean qui permet de faire cela.

    Voici le code de ma servlet
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    package servlet;
    
    import java.io.IOException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.HashSet;
    import java.util.Iterator;
    import java.util.Set;
    import java.util.StringTokenizer;
    
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import ejb.Document;
    import ejb.GestionDeDocument;
    import ejb.Modification;
    import ejb.Tag;
    import ejb.TypeDocument;
    import ejb.Utilisateur;
    
    public class AjouterDocument extends HttpServlet{
    	private String nom;
    	private Date date_creation;
    	private String emplacement;
    	private String listeTags;
    	private Set<Tag> tags ;
    	private String leType;
    	private TypeDocument type;
    	private Set<Modification> listeModification;
    	private Set<Document> listeDocument;
    	
    	// cette méthode permet de récupérer la requête envoyé par l'applet et de renvoyer la réponse
    	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
    		// instantiation d'un nouveau document
    		Document document = new Document();
    				
    		// récupération des paramètres envoyés par l'applet
    		
    		// le nom du document
    		nom = request.getParameter("nom");
    		
    		//l'emplacement
    		emplacement = request.getParameter("emplacement");
    		
    		// la liste des tags
    		listeTags = request.getParameter("tags"); // la liste de tags envoyée par l'applet est du style tag1|tag2|tag3
    		
    		// on récupère les tags un par un
    		
    		tags = new HashSet<Tag>();
    		StringTokenizer lesTags = new StringTokenizer(listeTags);
    		while(lesTags.hasMoreTokens()){
    			Tag t = new Tag();
    			String nomTag = lesTags.nextToken();
    			t.setNom(nomTag);
    			t.setCommentaire("");
    			tags.add(t); // on ajoute le tag dans la liste
    		}
    		
    		// le type du document
    		leType = request.getParameter("type");
    		type = new TypeDocument();
    		type.setNom(leType);
    		type.setCommentaire("");
    		
    		// la date de création
    		date_creation = new Date();
    		
    		
    		// modification
    		listeModification = new HashSet<Modification>();
    	/*	Modification modif = new Modification();
    		modif.setCommentaire("ajout");
    		modif.setDate(date_creation);
    		modif.setDocument(document);
    		
    		Utilisateur user = new Utilisateur();
    		user.setInitiale("YB");
    		user.setMotDePasse("motDePasse");
    		user.setNom("Bardon");
    		user.setPrenom("Yannick");
    		user.setModification(listeModification);
    		
    		modif.setUser(user);
    		*/
    		// on construit le nouveau document avec tous les paramètres
    		
    		document.setDate_creation(date_creation);
    		document.setEmplacement(emplacement);
    		document.setModification(listeModification);
    		document.setNom(nom);
    		document.setTag(tags);
    		document.setTypeDocument(type);
    		
    		
    		// le type correspond à plusieurs document donc c'est pour cela qu'on lui met une liste de document
    		listeDocument = new HashSet<Document>();
    		listeDocument.add(document);
    		
    		type.setDocument(listeDocument);
    		
    		
    		
    		
    		// on va faire appel aux ejb
    		
    		try {
    			Context context = new InitialContext();
    			GestionDeDocument gdd = (GestionDeDocument) context.lookup("GestionDeDocumentBean/remote");
    			// ajout d'un document dans la base de données
    			gdd.ajouterDocument(document);
    			
    			// ajout du tag dans la base de données
    			// le tag correspond à plusieurs document donc c'est pour cele qu'on lui met une liste de document
    			Iterator<Tag> iterator = tags.iterator();
    			while(iterator.hasNext()){
    				Tag t = iterator.next();
    				t.setDocument(listeDocument);
    				gdd.ajouterTag(t);
    			}
    			
    			// ajout du type dans la base de données
    			gdd.ajouterType(type);
    			/*gdd.ajouterModification(modif);
    			gdd.ajouterUser(user);
    			*/
    		} catch (NamingException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    
    		
    	}
    		
    
    }
    j'ai mis en rouge les parties importante

    Enfin une fois que je lance mon appli web via firefox, voici l'erreur que j'ai :

    type Rapport d'exception

    message
    description Le serveur a rencontré une erreur interne () qui l'a empêché de satisfaire la requête.

    exception

    javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of ejb.Document.modification
    org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:63)
    org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
    org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
    org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:278)
    org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:79)
    org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:70)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:103)
    $Proxy81.ajouterDocument(Unknown Source)
    servlet.AjouterDocument.doGet(AjouterDocument.java:116)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

    cause mère

    javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of ejb.Document.modification
    org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:629)
    org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:218)
    org.jboss.ejb3.entity.TransactionScopedEntityManager.persist(TransactionScopedEntityManager.java:182)
    ejb.GestionDeDocumentBean.ajouterDocument(GestionDeDocumentBean.java:32)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:585)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
    org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
    org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
    org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
    org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:278)
    org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:79)
    org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:70)
    org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:103)
    $Proxy81.ajouterDocument(Unknown Source)
    servlet.AjouterDocument.doGet(AjouterDocument.java:116)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    Je ne sais pas d'où cela peut venir

    Merci pour vos réponses

  2. #2
    Membre habitué Avatar de Rizzen
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    115
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 115
    Points : 157
    Points
    157
    Par défaut
    quand tu fais un persist sur ton document est ce que ton objet modif existe déjà dans la bdd ? Je veux dire par la est ce que tu l'as persister ou alors récupérer de la base ?

  3. #3
    Membre régulier
    Inscrit en
    Février 2008
    Messages
    222
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 222
    Points : 120
    Points
    120
    Par défaut
    salut,

    mon objet modif je l'ai persisté, en fait grace aux annotations des ejb3, du style @ManyToOne j'ai pu créer ma base de données avec mes différentes tables, et le problème est lorsque je veux ajouter un nouveau document dans la table j'ai le problème avec le champ modification, un problème sur le setter de modification je pense d'aprés l'erreur qu'il m'affiche, et je ne sais pas d'où peut venir le problème.

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 40
    Points : 47
    Points
    47
    Par défaut
    Hello

    Apparement, il persist un nouveau document.
    2 remarques cependant, même si je ne pense pas que ce soit la cause du problème:
    - tu mets des annotation a la fois sur les propriété (les @column) et aussi sur les getters. Je pense que ce n'est pas une bonne idée.
    - dans Document, le getter de modification renvoie un Collection alors qu'il devrait renvoyer un Set --> peut etre la cause de l'exception (même si ca m'étonnerait...)

  5. #5
    Membre régulier
    Inscrit en
    Février 2008
    Messages
    222
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 222
    Points : 120
    Points
    120
    Par défaut
    Salut,

    tes 2 remarques sont intéressentes, tu préconises plutôt que je mette toutes mes annotations sur les getters donc @Column aussi, je vais essayer de changer le type de retour du getter pour modification, on ne sait jamais si sa peut venir de là

  6. #6
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 40
    Points : 47
    Points
    47
    Par défaut
    Oui il vaut mieux éviter de mélanger la manière d'annoter les classes, et ce sur la totalité du projet pas seulement sur dans la même classe.

  7. #7
    Membre régulier
    Inscrit en
    Février 2008
    Messages
    222
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 222
    Points : 120
    Points
    120
    Par défaut
    je viens de faire les modificatiosn et malheureusesement j'ai toujours les même erreurs, par contre j'ai une erreur sur la console window du serveur d'application qui est la suivante, que je n'avais pas vu avant

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    10:46:35,774 ERROR [BasicPropertyAccessor] expected type : java.util.Set, actual value : org.hibernate.collection.PersistentBag

  8. #8
    Membre régulier
    Inscrit en
    Février 2008
    Messages
    222
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 222
    Points : 120
    Points
    120
    Par défaut
    Oups, petit rectificatif lorsque j'ai changé la valeur de retour de getter pour modification il y a eu un changement, en effet, je n'ai pas la même erreur, voici cette erreur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
     
    java.lang.RuntimeException: javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Can't commit because the transaction is in aborted state
    	org.jboss.aspects.tx.TxPolicy.handleEndTransactionException(TxPolicy.java:198)
    	org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:180)
    	org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
    	org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
    	org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:278)
    	org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:79)
    	org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:70)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:103)
    	$Proxy81.ajouterDocument(Unknown Source)
    	servlet.AjouterDocument.doGet(AjouterDocument.java:116)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
     
    cause mère
     
    javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Can't commit because the transaction is in aborted state
    	com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1267)
    	com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
    	com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
    	org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
    	org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
    	org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
    	org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:278)
    	org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:79)
    	org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:70)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:103)
    	$Proxy81.ajouterDocument(Unknown Source)
    	servlet.AjouterDocument.doGet(AjouterDocument.java:116)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    C'est parti pour faire des recherches sur le net...

  9. #9
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 40
    Points : 47
    Points
    47
    Par défaut
    Je pense pas que tu trouveras quelque chose d'utile sur le net, cette exception est "générique", elle veut dure qu'il y a eu un problème au niveau du persist/merge, sans en dire plus.
    Il faudrait que l'on voit le code de GestionDeDocumentBean.ajouterDocument() pour voir ce qui ne va pas.

  10. #10
    Membre régulier
    Inscrit en
    Février 2008
    Messages
    222
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 222
    Points : 120
    Points
    120
    Par défaut
    En effet, je n'ai pas trouvé grand chose sur le net.
    Voici mes 5 fichiers java qui représente mes tables dans ma base de données :

    document.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
     
    @Entity
    public class Document implements Serializable{
    	// les variables correspondent aux colonnes de la table Document de la base de données
     
    	private String nom; // le nom du document
     
    	private java.util.Date date_creation; // la date de création du document
     
    	private String emplacement; // l'emplacement du document
     
    	private java.util.Set<Modification> modification; // la date de dernière modification
     
    	private java.util.Set<Tag> tag; // la liste des tags représentant ce document
    	private static final long serialVersionUID = -728268157L; 
    	private Long id; // l'identifiant obligatoire pour la table
     
    	private TypeDocument typeDocument; // le type du document : ex technique, commercial ..
     
     
    	// le constructeur qui est vide
     
    	public Document() {
    		super();
    	}
     
     
    	// redéfinition de la méthode ToString
     
    	public String toString() {
    		return "Document" + " nom=" + nom + " date_creation=" + date_creation
    				+ " emplacement=" + emplacement + " id=" + id;
    	}
     
     
    	// les getters et setters
    	@Column(name = "nom", nullable = false)
    	public String getNom() {
    		return this.nom;
    	}
     
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
    	@Column(name = "date_creation", nullable = false)
    	public java.util.Date getDate_creation() {
    		return this.date_creation;
    	}
     
     
    	public void setDate_creation(java.util.Date date_creation) {
    		this.date_creation = date_creation;
    	}
     
    	@Column(name = "emplacement", nullable = false)
    	public String getEmplacement() {
    		return this.emplacement;
    	}
     
     
    	public void setEmplacement(String emplacement) {
    		this.emplacement = emplacement;
    	}
     
           @Column(name = "modification", nullable = false)
    	@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "document")
    	public Set<Modification> getModification() {
    		if (modification == null) {
    			modification = new java.util.HashSet<Modification>();
    		}
    		return modification;
    	}
     
     
    	public void setModification(java.util.Set<Modification> modification) {
    		this.modification = modification;
    	}
     
     
    	public void addModification(Modification Modification) {
    		getModification().add(Modification);
    	}
     
     
    	public void removeModification(Modification Modification) {
    		getModification().remove(Modification);
    	}
     
     
     
    	@Column(name = "tag", nullable = false)
    	@ManyToMany(cascade=CascadeType.ALL, mappedBy="document", targetEntity=Tag.class) 
    	public java.util.Set<Tag> getTag() {
    		if (tag == null) {
    			tag = new java.util.HashSet<Tag>();
    		}
    		return tag;
    	}
     
     
    	public void setTag(java.util.Set<Tag> tag) {
    		this.tag = tag;
    	}
     
     
    	public void addTag(Tag tag) {
    		getTag().add(tag);
    	}
     
     
    	public void removeTag(Tag tag) {
    		getTag().remove(tag);
    	}
     
    	@Id // tag définissant la clé primaire
    	@GeneratedValue(strategy=GenerationType.AUTO) // tag indiquant que la clé est auto générée
    	public Long getId() {
    		return this.id;
    	}
     
     
    	public void setId(Long id) {
    		this.id = id;
    	}
     
            @Column(name = "typeDocument", nullable = false)
    	@ManyToOne
    	@JoinColumn(name = "typeDocumentID")
    	public TypeDocument getTypeDocument() {
    		return this.typeDocument;
    	}
     
     
    	public void setTypeDocument(TypeDocument typeDocument) {
    		this.typeDocument = typeDocument;
    	}
     
     
     
    }
    Modification.java :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
     
    @Entity
    public class Modification implements Serializable {
    	// les variables correspondent aux colonnes de la table Modification de la base de données
     
    	private java.util.Date date; // la date de modification
     
    	private String commentaire; // le commentaire pour expliqué ce qu'il a été fait comme modification
     
    	private Document document; // représente le document qui a été modifié
    	private Utilisateur user; // représente le user qui a fait cette modification
    	private static final long serialVersionUID = 258313988L;
    	private Long id; // identifiant obligatoire pour la table
     
    	// redéfinition de la méthode toString
     
    	public String toString() {
    		return "Modification" + " date=" + date + " commentaire=" + commentaire
    				+ " id=" + id;
    	}
     
    	// le constructeur vide
     
    	public Modification() {
    		super();
    	}
     
    	// les getters et les setters
     
            @Column(name = "date", nullable = false)
    	public java.util.Date getDate() {
    		return this.date;
    	}
     
     
    	public void setDate(java.util.Date date) {
    		this.date = date;
    	}
     
    	@Column(name = "commentaire", nullable = false)
    	public String getCommentaire() {
    		return this.commentaire;
    	}
     
     
    	public void setCommentaire(String commentaire) {
    		this.commentaire = commentaire;
    	}
     
    	@Column(name = "documentID", nullable = false)
    	@ManyToOne
    	@JoinColumn(name = "documentID")
    	public Document getDocument() {
    		return this.document;
    	}
     
     
    	public void setDocument(Document document) {
    		this.document = document;
    	}
     
    	@ManyToOne
    	@JoinColumn(name = "UserID")
    	public Utilisateur getUser() {
    		return this.user;
    	}
     
     
    	public void setUser(Utilisateur user) {
    		this.user = user;
    	}
     
    	@Id // tag définissant la clé primaire
    	@GeneratedValue(strategy=GenerationType.AUTO) // tag indiquant que la clé est auto générée
    	public Long getId() {
    		return this.id;
    	}
     
     
    	public void setId(Long id) {
    		this.id = id;
    	}
     
    }
    Tag.java :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
     
    @Entity
    public class Tag implements Serializable {
    	//les variables correspondent aux colonnes de la table Tag de la base de données
     
    	private String nom; // nom du tag
     
    	private String commentaire; // le commentaire associé
     
    	private java.util.Set<Document> document; // un tag peut être associé à plusieurs documents
    	private static final long serialVersionUID = 820497714L;
     
     
    	private Long id; // identifiant obligatoire pour la table
     
    	// le constructeur vide
     
    	public Tag() {
    		super();
    	}
     
    	// redéfinition de la méthode toString
     
    	public String toString() {
    		return "Tag" + " nom=" + nom + " commentaire=" + commentaire + " id="
    				+ id;
    	}
     
    	// les getters et les setters
    	@Column(name = "nom", nullable = false)
    	public String getNom() {
    		return this.nom;
    	}
     
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
    	@Column(name = "commentaire", nullable = false)
    	public String getCommentaire() {
    		return this.commentaire;
    	}
     
     
    	public void setCommentaire(String commentaire) {
    		this.commentaire = commentaire;
    	}
     
            @Column(name = "document", nullable = false)
    	@ManyToMany
    	public java.util.Set<Document> getDocument() {
    		if (document == null) {
    			document = new java.util.HashSet<Document>();
    		}
    		return document;
    	}
     
     
    	public void setDocument(java.util.Set<Document> document) {
    		this.document = document;
    	}
     
     
    	public void addDocument(Document document) {
    		getDocument().add(document);
    	}
     
     
    	public void removeDocument(Document document) {
    		getDocument().remove(document);
    	}
     
    	@Id // tag définissant la clé primaire
    	@GeneratedValue(strategy=GenerationType.AUTO) // tag indiquant que la clé est auto générée
    	public Long getId() {
    		return this.id;
    	}
     
     
    	public void setId(Long id) {
    		this.id = id;
    	}
    }
    TypeDocument.java :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
     
    @Entity
    public class TypeDocument implements java.io.Serializable {
    	//les variables correspondent aux colonnes de la table TypeDocument de la base de données
     
    	private String nom; //le nom du type ex : technique, commercial
     
    	private String commentaire; // le commentaire associé
    	private static final long serialVersionUID = -1423726627L;
    	private Long id; // identifiant obligatoire pour la table
     
    	private Set<Document> document; //représente le document associée
     
    	// le constructeur vide
     
    	public TypeDocument() {
    		super();
    	}
     
    	// les getters et les setters
    	@Column(name = "nom", nullable = false)
    	public String getNom() {
    		return this.nom;
    	}
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
            @Column(name = "commentaire", nullable = false)
    	public String getCommentaire() {
    		return this.commentaire;
    	}
     
     
    	public void setCommentaire(String commentaire) {
    		this.commentaire = commentaire;
    	}
     
    	@Id // tag définissant la clé primaire
    	@GeneratedValue(strategy=GenerationType.AUTO) // tag indiquant que la clé est auto générée
    	public Long getId() {
    		return this.id;
    	}
     
     
    	public void setId(Long id) {
    		this.id = id;
    	}
     
            @Column(name = "document", nullable = false)
    	@OneToMany(mappedBy="typeDocument")
    	public Set<Document> getDocument() {
    		if (document == null) {
    			document = new java.util.HashSet<Document>();
    		}
    		return document;
    	}
     
     
     
    	public void setDocument(Set<Document> document) {
    		this.document = document;
    	}
     
    	public void addDocument(Document document) {
    		getDocument().add(document);
    	}
     
     
    	public void removeDocument(Document document) {
    		getDocument().remove(document);
    	}
     
     
    	// redéfinition de la méthode toString
     
    	public String toString() {
    		return "TypeDocument" + " nom=" + nom + " commentaire=" + commentaire
    				+ " id=" + id;
    	}
    }
    Utilisateur.java :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
     
    @Entity
    public class Utilisateur implements java.io.Serializable {
     
    	private String nom;
     
    	private String prenom;
     
    	private String motDePasse;
     
    	private String initiale;
    	private Set<Modification> modification;
    	private static final long serialVersionUID = -334327501L;
    	private Long id;
     
     
    	public Utilisateur() {
    		super();
    	}
     
     
    	public String toString() {
    		return "User" + " nom=" + nom + " Prenom=" + prenom + " motDePasse="
    				+ motDePasse + " initiale=" + initiale + " id=" + id;
    	}
     
    	@Column(name = "nom", nullable = false)
    	public String getNom() {
    		return this.nom;
    	}
     
     
    	public void setNom(String nom) {
    		this.nom = nom;
    	}
     
    	@Column(name = "prenom", nullable = false)
    	public String getPrenom() {
    		return this.prenom;
    	}
     
     
    	public void setPrenom(String Prenom) {
    		this.prenom = Prenom;
    	}
     
    	@Column(name = "motDePasse", nullable = false)
    	public String getMotDePasse() {
    		return this.motDePasse;
    	}
     
     
    	public void setMotDePasse(String motDePasse) {
    		this.motDePasse = motDePasse;
    	}
     
    	@Column(name = "initiale", nullable = false)
    	public String getInitiale() {
    		return this.initiale;
    	}
     
     
    	public void setInitiale(String initiale) {
    		this.initiale = initiale;
    	}
     
     
    	@Column(name = "modification", nullable = false)
    	@OneToMany(mappedBy="user")
    	public Set<Modification> getModification() {
    		if (modification == null) {
    			modification = new java.util.HashSet<Modification>();
    		}
    		return modification;
    	}
     
     
    	public void setModification(Set<Modification> modification) {
    		this.modification = modification;
    	}
     
    	public void addDocument(Modification modification) {
    		getModification().add(modification);
    	}
     
     
    	public void removeDocument(Document document) {
    		getModification().remove(document);
    	}
     
     
    	@Id // tag définissant la clé primaire
    	@GeneratedValue(strategy=GenerationType.AUTO) // tag indiquant que la clé est auto générée
    	public Long getId() {
    		return this.id;
    	}
     
     
    	public void setId(Long id) {
    		this.id = id;
    	}
    }
    Ensuite voici l' EJB session bean donc l'interface et l'implémentation :

    GestionDeDocument.java :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    @Remote
    public interface GestionDeDocument {
    	public void ajouterDocument(Document document);
    	public void ajouterTag(Tag tag);
    	public void ajouterType(TypeDocument type);
    	public void ajouterUser(Utilisateur user);
    	public void ajouterModification(Modification modification);
    	public void supprimerDocument(Document document);
    	public List<Document> RechercherDocument(Document document, Tag tag);
    	public List<Document> AfficherDocumentTechnique();
    	public List<Document> AfficherDocumentCommercial();
     
    }
    GestionDeDocumentBean.java

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
     
    @Stateless
    public class GestionDeDocumentBean implements GestionDeDocument{
     
    	@PersistenceContext
    	EntityManager em;
     
     
    	public List<Document> AfficherDocumentCommercial() {
     
    		return null;
    	}
     
    	public List<Document> AfficherDocumentTechnique() {
     
    		return null;
    	}
     
    	public List<Document> RechercherDocument(Document document, Tag tag) {
     
    		return null;
    	}
     
    	public void ajouterDocument(Document document) {
    		em.persist(document);
     
    	}
     
    	public void supprimerDocument(Document document) {
    		em.remove(document);
     
     
    	}
     
    	public void ajouterTag(Tag tag) {
    		em.persist(tag);
     
    	}
     
    	public void ajouterType(TypeDocument type) {
    		em.persist(type);
     
    	}
     
    	public void ajouterModification(Modification modification) {
    		em.persist(modification);
     
    	}
     
    	public void ajouterUser(Utilisateur user) {
    		em.persist(user);
     
    	}
     
     
    }
    J'ai donc consiédé qu'un document peut subir plusieurs modification, une modification correspond à un document, un utilisateur fait plusieurs modifications, une modification est faite par un utilisateur, un document à un seul type et un type correspond à plusieurs document, et enfin un document à plusieurs tags et un tag correspond à plusieurs document

  11. #11
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 40
    Points : 47
    Points
    47
    Par défaut
    J'avoue ne pas être trop entré dans les détails de ton code.
    Mais je pense que ton erreur vient du fait que les hashCode() et equals() de tes entity ne sont pas codés.
    Cherche sur le net a quoi servent ces méthodes pour la persistance avec hibernate.
    Tiens moi au courant

  12. #12
    Membre régulier
    Inscrit en
    Février 2008
    Messages
    222
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 222
    Points : 120
    Points
    120
    Par défaut
    Bon et bien je viens de regarder hascode et equals que j'ai ajouté dans mes entity bean mais malheureusement, ça n'a rien changé, ensuite aprés quelques recherches sur le net j'ai trouvé quelques pistes mais je n'ai rien trouvé de concluant.

    Donc j'ai toujours le même problème.
    Je vais de nouveau exposer mon problème,
    J'ai une base de données avec 5 tables dont ces 2 tables Document et TypeDocument, entre ces deux tables il y a une realtion @OneToMany, mais lorsque je veux ajouter un nouveau document voici l'erreur qui s'affiche :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
     
    type Rapport d'exception
     
    message
     
    description Le serveur a rencontré une erreur interne () qui l'a empêché de satisfaire la requête.
     
    exception
     
    java.lang.RuntimeException: javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Can't commit because the transaction is in aborted state
    	org.jboss.aspects.tx.TxPolicy.handleEndTransactionException(TxPolicy.java:198)
    	org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:180)
    	org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
    	org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
    	org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:278)
    	org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:79)
    	org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:70)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:103)
    	$Proxy81.ajouterDocument(Unknown Source)
    	servlet.AjouterDocument.doGet(AjouterDocument.java:134)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
     
    cause mère
     
    javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] [com.arjuna.ats.internal.jta.transaction.arjunacore.commitwhenaborted] Can't commit because the transaction is in aborted state
    	com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1267)
    	com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
    	com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
    	org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
    	org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
    	org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
    	org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:278)
    	org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:79)
    	org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:70)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:103)
    	$Proxy81.ajouterDocument(Unknown Source)
    	servlet.AjouterDocument.doGet(AjouterDocument.java:134)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
     
    cause mère
     
    java.lang.IllegalStateException: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: ejb.Document.typeDocument -> ejb.TypeDocument
    	org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:626)
    	org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:524)
    	com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
    	com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:249)
    	com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:88)
    	com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
    	com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1256)
    	com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
    	com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
    	org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
    	org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
    	org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
    	org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:278)
    	org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:79)
    	org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:70)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:103)
    	$Proxy81.ajouterDocument(Unknown Source)
    	servlet.AjouterDocument.doGet(AjouterDocument.java:134)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
     
    cause mère
     
    org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: ejb.Document.typeDocument -> ejb.TypeDocument
    	org.hibernate.engine.CascadingAction$9.noCascade(CascadingAction.java:353)
    	org.hibernate.engine.Cascade.cascade(Cascade.java:139)
    	org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:131)
    	org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:122)
    	org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
    	org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
    	org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
    	org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
    	org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
    	com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:114)
    	com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:249)
    	com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:88)
    	com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:177)
    	com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1256)
    	com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:135)
    	com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:87)
    	org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
    	org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
    	org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:77)
    	org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:278)
    	org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:79)
    	org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:70)
    	org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
    	org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:103)
    	$Proxy81.ajouterDocument(Unknown Source)
    	servlet.AjouterDocument.doGet(AjouterDocument.java:134)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    	org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    Si quelqu'un sait d'où ça vient, je suis preneur

  13. #13
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 40
    Points : 47
    Points
    47
    Par défaut
    Désolé c'est encore moi qui répond.
    Avec la totalité de l'exception c'est bien mieux, elle te dit clairement qu'il faut sauver TypeDocument avant de sauver Document. Donc soit tu le persistes avant, soit tu mets un cascade sur le manyToOne...

  14. #14
    Membre régulier
    Inscrit en
    Février 2008
    Messages
    222
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 222
    Points : 120
    Points
    120
    Par défaut
    Salut, ça ne me dérange pas du tou que sa soit toi qui réponde, au contraire

    En effet, ce matin j'ai mis dans @ManyToOne l'attribut cascade= CascadeTyep.all, du coup mon annotation sur le getter devient :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    @OneToMany(mappedBy="typeDocument", fetch=FetchType.EAGER, cascade = CascadeType.ALL)
    	public Set<Document> getDocument() {
    		if (document == null) {
    			document = new java.util.HashSet<Document>();
    		}
    		return document;
    	}
    Par contre ça ajoute un nouveau document, un type, les tags mais ça n'ajoute pas tout à fait comme je voudrais, il faut que je regarde encore et encore.

    Tu parles,qu'il faut sauver TypeDocument avant de sauver Document. Donc soit tu le persistes avant, soit tu mets un cascade sur le manyToOne...

    Comment faire pour sauver TypeDocument avant Document, et donc comment le persister avant,

    et oui moi aussi je t'embête toujours avec mes questions

Discussions similaires

  1. Réponses: 3
    Dernier message: 21/06/2012, 13h00
  2. EJB entity bean et LazyInitializationException
    Par bard123 dans le forum JPA
    Réponses: 27
    Dernier message: 13/03/2008, 17h14
  3. EJB Entity Bean
    Par bard123 dans le forum JPA
    Réponses: 10
    Dernier message: 04/03/2008, 12h36
  4. Réponses: 1
    Dernier message: 28/04/2007, 20h26
  5. problème de deploiement d'un Entity Bean CMP
    Par med56 dans le forum JOnAS
    Réponses: 1
    Dernier message: 19/09/2006, 12h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo