Insérer dans une table d'association
Bonjour,
Je peux pas insérer dans une association table "Affectation" qui associe deux tables: user et Demande
Il me donne une exception Transaction aborted.
Voilà le Model JPA de la classe Affectation:
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 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
|
package com.src.jpa;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
@Entity
@Table(name = "affectation", catalog = "datagta", schema = "")
@XmlRootElement
@NamedQueries({
@NamedQuery(name = "Affectation.findAll", query = "SELECT a FROM Affectation a"),
@NamedQuery(name = "Affectation.findByMat", query = "SELECT a FROM Affectation a WHERE a.affectationPK.mat = :mat"),
@NamedQuery(name = "Affectation.findByNumDmd", query = "SELECT a FROM Affectation a WHERE a.affectationPK.numDmd = :numDmd"),
@NamedQuery(name = "Affectation.findByDateAffectation", query = "SELECT a FROM Affectation a WHERE a.dateAffectation = :dateAffectation")})
public class Affectation implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected AffectationPK affectationPK;
@Column(name = "date_affectation")
@Temporal(TemporalType.DATE)
private Date dateAffectation;
@JoinColumn(name = "numDmd", referencedColumnName = "numDmd", insertable = false, updatable = false)
@ManyToOne(optional = false)
private Demande demande;
public Affectation() {
}
public Affectation(AffectationPK affectationPK) {
this.affectationPK = affectationPK;
}
public Affectation(int mat, int numDmd) {
this.affectationPK = new AffectationPK(mat, numDmd);
}
public AffectationPK getAffectationPK() {
return affectationPK;
}
public void setAffectationPK(AffectationPK affectationPK) {
this.affectationPK = affectationPK;
}
public Date getDateAffectation() {
return dateAffectation;
}
public void setDateAffectation(Date dateAffectation) {
this.dateAffectation = dateAffectation;
}
public Demande getDemande() {
return demande;
}
public void setDemande(Demande demande) {
this.demande = demande;
}
@Override
public int hashCode() {
int hash = 0;
hash += (affectationPK != null ? affectationPK.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Affectation)) {
return false;
}
Affectation other = (Affectation) object;
if ((this.affectationPK == null && other.affectationPK != null) || (this.affectationPK != null && !this.affectationPK.equals(other.affectationPK))) {
return false;
}
return true;
}
@Override
public String toString() {
return "com.src.jpa.Affectation[ affectationPK=" + affectationPK + " ]";
}
} |
AffectationPK.java
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 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
|
package com.src.jpa;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.validation.constraints.NotNull;
@Embeddable
public class AffectationPK implements Serializable {
@Basic(optional = false)
@Column(name = "mat")
private int mat;
@Basic(optional = false)
@Column(name = "numDmd")
private int numDmd;
public AffectationPK() {
}
public AffectationPK(int mat, int numDmd) {
this.mat = mat;
this.numDmd = numDmd;
}
public int getMat() {
return mat;
}
public void setMat(int mat) {
this.mat = mat;
}
public int getNumDmd() {
return numDmd;
}
public void setNumDmd(int numDmd) {
this.numDmd = numDmd;
}
@Override
public int hashCode() {
int hash = 0;
hash += (int) mat;
hash += (int) numDmd;
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof AffectationPK)) {
return false;
}
AffectationPK other = (AffectationPK) object;
if (this.mat != other.mat) {
return false;
}
if (this.numDmd != other.numDmd) {
return false;
}
return true;
}
@Override
public String toString() {
return "com.src.jpa.AffectationPK[ mat=" + mat + ", numDmd=" + numDmd + " ]";
}
} |
Est ce que le problème est au niveau de la classe model??
J'utilise l'architecture JPA/EJB/JSF
Merci.
Association Affectation AffectationPK
Bonjour,
Dans le combobox user, normalement je veux sélectionner matricule de user selon le choix, Cependant, il affiche dans la zone texte "com.src.jpa.Affectation[AffectatioPK=com.src.jpa.Affectation[mat=6, numDmd=1]]"
Lorsque je clique sur Enregistrer il me donne ce type d'erreur:
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 38 39 40 41 42 43 44 45 46 47 48
|
java.lang.NumberFormatException: For input string: "6#1"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:492)
at java.lang.Integer.valueOf(Integer.java:582)
at com.src.jsf.UserController$UserControllerConverter.getKey(UserController.java:261)
at com.src.jsf.UserController$UserControllerConverter.getAsObject(UserController.java:256)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:171)
at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(MenuRenderer.java:202)
at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(MenuRenderer.java:319)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
at javax.faces.component.UIInput.validate(UIInput.java:960)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1233)
at javax.faces.component.UIInput.processValidators(UIInput.java:698)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIForm.processValidators(UIForm.java:253)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:744) |