je veux supprimer une occurence de la table BCN dans la base de données
Hibernate a creé la classe correspondante a la table et voila son code :
package stt;
import stt.base.BaseBcn;
public class Bcn extends BaseBcn { private static final long serialVersionUID = 1L;
/*[CONSTRUCTOR MARKER BEGIN]*/ public Bcn () { super(); }
/** * Constructor for primary key */ public Bcn (stt.BcnPK id) { super(id); }
/** * Constructor for required fields */ public Bcn ( stt.BcnPK id, java.lang.Integer nfin, java.util.Date dtBcn, java.lang.Integer cdart, java.lang.Integer nbcn, java.lang.String cddep, java.lang.String logincreateur, java.util.Date datecreation, java.lang.String loginModificateur, java.util.Date dateModification) {
super ( id, nfin, dtBcn, cdart, nbcn, cddep, logincreateur, datecreation, loginModificateur, dateModification); }
/*[CONSTRUCTOR MARKER END]*/
aussi que la classe BCNPK :
package stt;
import stt.base.BaseBcnPK;
public class BcnPK extends BaseBcnPK { private static final long serialVersionUID = 1L;
/*[CONSTRUCTOR MARKER BEGIN]*/ public BcnPK () {}
public BcnPK ( java.lang.String serie, java.lang.Integer ndebut, java.lang.String idTitre) {
super ( serie, ndebut, idTitre); } /*[CONSTRUCTOR MARKER END]*/
}
j'ai créer une classe SuppressionBcn dont le code est le suivant :
import java.util.Date; import java.util.Iterator;
import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration;
import stt.Bcn; import stt.BcnPK; import stt.dao.BcnDAO; import stt.dao._RootDAO;
public class SuppressionBcnBean
{ private String Titre; private String serie; private int ndeb; private int nfin; private int qte; private int numbcn; private Date dtbcn; private int cdart; private String cddep; private String logincre; private Date datecre; private String loginmod; private Date datemod; private String msg; public SuppressionBcnBean(){}
public String getMsg() { return msg; }
public void setMsg(String msg) { this.msg = msg; }
public String getLogincre() { return logincre; }
public void setLogincre(String logincre) { this.logincre = logincre; }
public Date getDatecre() { return datecre; }
public void setDatecre(Date datecre) { this.datecre = datecre; }
public String getLoginmod() { return loginmod; }
public void setLoginmod(String loginmod) { this.loginmod = loginmod; }
public Date getDatemod() { return datemod; }
public void setDatemod(Date datemod) { this.datemod = datemod; }
public int getCdart() { return cdart; } public void setCdart(int cdart) { this.cdart = cdart; } public String getCddep() { return cddep; } public void setCddep(String cddep) { this.cddep = cddep; }
public String getTitre() { return Titre; } public void setTitre(String titre) { Titre = titre; } public String getSerie() { return serie; } public void setSerie(String serie) { this.serie = serie; } public int getNdeb() { return ndeb; } public void setNdeb(int ndeb) { this.ndeb = ndeb; } public int getNfin() { return nfin; } public void setNfin(int nfin) { this.nfin = nfin; } public int getQte() { return qte; } public void setQte(int qte) { this.qte = qte; } public int getNumbcn() { return numbcn; } public void setNumbcn(int numbcn) { this.numbcn = numbcn; } public Date getDtbcn() { return dtbcn; } public void setDtbcn(Date dtbcn) { this.dtbcn = dtbcn; }
public String supprimer() {
SessionFactory sessionfactory = new Configuration().configure().buildSessionFactory(); Session session = sessionfactory.openSession(); try { BcnDAO dao = new BcnDAO(); Query q= session.createQuery ("from bcn as b where b.Id.idTitre=:idt and b.Id.serie=:s and b.Id.ndebut=: nd and b.nfin=: nf and b.dtBcn=:dt and b.nbcn=:nb"); q.setString("idt", this.Titre); q.setString("s",this.serie); q.setInteger("nd",this.ndeb); q.setInteger("nf",this.nfin); q.setDate("dt",this.dtbcn); q.setInteger("nb",this.numbcn); Iterator it = q.iterate(); while (it.hasNext()) { Bcn b = (Bcn) it.next(); this.cdart=b.getCdart(); this.cddep=b.getCddep(); this.logincre=b.getLogincreateur(); this.datecre=b.getDatecreation(); this.loginmod=b.getLoginModificateur(); this.datemod=b.getDateModification(); }
Bcn bb = new Bcn(new BcnPK(this.serie,this.ndeb,this.Titre),this.nfin,this.dtbcn,this.cdart,this.numbcn,this.cddep,this.logincre,this.datecre,this.loginmod,this.datemod); dao.delete(bb); this.msg="Suppression effectué"; return "ok";
}
catch(HibernateException e) { this.msg="Suppression non effectue"; return "nok";
} finally { session.close(); }
}
}
et j'ai conçu une page jsp dont le code est le suivant :
<h1 style="font-size: 30px; font-family: arial; color:blue">SUPPRESSION B.C.N</h1>
<h:panelGrid columns="2" border="5" style="background-color:Orange">
<h:outputText value="Titre"></h:outputText> <h:inputText id="title" value="#{suppressionBcnBean.titre}"></h:inputText> <h:outputText value="Serie"></h:outputText> <h:inputText id="serie" value="#{suppressionBcnBean.serie}"></h:inputText> <h:outputText value="Premier N° B.C.N"></h:outputText> <h:inputText id="premier" value="#{suppressionBcnBean.ndeb}"></h:inputText> <h:outputText value="Dernier N° B.C.N"></h:outputText> <h:inputText id="dernier" value="#{suppressionBcnBean.nfin}"></h:inputText> <h:outputText value="Quantité"></h:outputText> <h:inputText id="quantity" value="#{suppressionBcnBean.qte}"></h:inputText> <h:outputText value="Numero B.C.N"></h:outputText> <h:inputText id="numbcn" value="#{suppressionBcnBean.numbcn}"></h:inputText> <h:outputText value="Date B.C.N"></h:outputText> <h:inputText id="datebcn" value="#{suppressionBcnBean.dtbcn}"><f:convertDateTime pattern="yyyy-MM-dd"/></h:inputText><h:message for="datebcn" id="mess1"></h:message>
</h:panelGrid>
<br/><br/>
<h:panelGrid columns="2">
<center>
<h:commandButton value="Supprimer" type="submit"style="font-size: 18px; background-color: Orange" action="#{suppressionBcnBean.supprimer}"></h:commandButton>
<h:commandButton value="Reinitialiser" type="reset" style=" font-size:18px; background-color: Orange"></h:commandButton>
</center>
</h:panelGrid>
<br/>
<h:panelGrid columns="1">
<h:outputText value="#{suppressionBcnBean.msg}"></h:outputText>
</h:panelGrid>
</h:form> </center> </body> </f:view> </html>
le console affiche les erreurs suivantes et la suppression ne s'effectue pas :
39 [http-8080-1] INFO org.hibernate.cfg.Environment - Hibernate 3.3.0.SP1 47 [http-8080-1] INFO org.hibernate.cfg.Environment - hibernate.properties not found 53 [http-8080-1] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist 64 [http-8080-1] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling 210 [http-8080-1] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml 210 [http-8080-1] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml 341 [http-8080-1] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : Bcn.hbm.xml 470 [http-8080-1] INFO org.hibernate.cfg.HbmBinder - Mapping class: stt.Bcn -> bcn 507 [http-8080-1] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : Prix.hbm.xml 532 [http-8080-1] INFO org.hibernate.cfg.HbmBinder - Mapping class: stt.Prix -> prix 532 [http-8080-1] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : StkRvt.hbm.xml 563 [http-8080-1] INFO org.hibernate.cfg.HbmBinder - Mapping class: stt.StkRvt -> stk_rvt 564 [http-8080-1] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : DefBcn.hbm.xml 579 [http-8080-1] INFO org.hibernate.cfg.HbmBinder - Mapping class: stt.DefBcn -> def_bcn 579 [http-8080-1] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null 943 [http-8080-1] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!) 943 [http-8080-1] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20 943 [http-8080-1] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false 949 [http-8080-1] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/transtu 949 [http-8080-1] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=root, password=****} 1271 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - RDBMS: MySQL, version: 4.1.9-max 1271 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.10 ( Revision: ${svn.Revision} ) 1306 [http-8080-1] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.MySQLDialect 1317 [http-8080-1] INFO org.hibernate.transaction.TransactionFactoryFactory - Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory 1322 [http-8080-1] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended) 1322 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled 1322 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled 1322 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15 1322 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled 1324 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled 1324 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled 1324 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto 1325 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth: 2 1325 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1 1325 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled 1325 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled 1325 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled 1326 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory 1331 [http-8080-1] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory 1331 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {} 1331 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled 1331 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled 1331 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled 1331 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory 1331 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled 1331 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled 1345 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled 1345 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled 1346 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo 1346 [http-8080-1] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled 1434 [http-8080-1] INFO org.hibernate.impl.SessionFactoryImpl - building session factory 1884 [http-8080-1] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
que dois je faire comme rectification ?
|