[HIBERNATE] Delete d'un objet
Bonsoir je me pose une question par rapport à une suppression d'un objet identifié par son id... Je travaille avec Hibernate 3
Voici le code que j'utilise pour cela
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
public void deleteMember(Long memberID) {
// DAO to delete
MemberDAO memberDAO = null;
try {
Session session = HibernateHelper.currentSession();
// Loading object
memberDAO = (MemberDAO) session.get(MemberDAO.class, memberID);
// Deleting object
session.delete(memberDAO);
} catch (HibernateException e) {
} finally {
HibernateHelper.closeSession();
}
} |
Je dois loader l'objet persistant avant de pouvoir le supprimer, jusqu'ici tout est normal mais n'y a t il pas un moyen plus simple pour supprimer un objet identifié par son id???
Merci
Suppression d'une occurence
j'ai fais ce code afin de supprimer une occurence de la Table Bcn :
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 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 152
|
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()
{
boolean verif = false;
SessionFactory sessionfactory = new Configuration().configure().buildSessionFactory();
Session session = sessionfactory.openSession();
try
{
String hqlDelete = "delete Bcn where idTitre=:tt";
session.createQuery( hqlDelete ).setString( "tt",this.Titre );
verif = true;
}
finally
{
session.close();
}
sessionfactory.close();
if ( verif = true)
{
this.msg="Suppression effectue";
return "ok";
}
else
{
this.msg = "Suppression non effectué";
return "nok";
}
}
} |
*
Lors de l'execution y avait pas une exception et dans ma page jsp s'affiche le message "suppresion effectue " or lorque j'ai consulté la base la ligne existe encore
quel rectification dois je faire svp ? et merci