- This topic has 1 reply, 2 voices, and was last updated 18 years, 10 months ago by
Riyad Kalla.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
ouafaaMemberhello,
im new in EJB/hibernate developement.
i work with myeclipse/Hibernate to develop a web application with mysql database.
i created the mapping.
when i created a client class to insert something in database i have this NullPointerException
any help will be appreciated.this is my table
create table ANNEE ( ID_AN int not null auto_increment, AN int not null, primary key (ID_AN) ) type = InnoDB;
this table is one to many related to an other table periodes:
create table PERIODE ( ID_PERIODE int not null auto_increment, ID_AN int not null, NOM_PERIODE varchar(30) not null, primary key (ID_PERIODE) ) type = InnoDB;
the class created is :
import java.util.HashSet; import java.util.Set; /** * Annee generated by MyEclipse - Hibernate Tools */ public class Annee implements java.io.Serializable { private Integer idAn; private Integer an; private Set periodes = new HashSet(0); /** default constructor */ public Annee() { } /** minimal constructor */ public Annee(Integer an) { this.an = an; } /** full constructor */ public Annee(Integer an, Set periodes) { this.an = an; this.periodes = periodes; } // Property accessors public Integer getIdAn() { return this.idAn; } public void setIdAn(Integer idAn) { this.idAn = idAn; } public Integer getAn() { return this.an; } public void setAn(Integer an) { this.an = an; } public Set getPeriodes() { return this.periodes; } public void setPeriodes(Set periodes) { this.periodes = periodes; }
the client class is
import org.hibernate.*; import org.hibernate.cfg.*; public class AjoutAnnee { public static void main( String [] argv) throws Exception, MappingException, HibernateException { Transaction tx=null; Session session=null; try { Configuration cfg = new Configuration().addClass(Annee.class); SessionFactory sessionFactory = cfg.buildSessionFactory(); // ouverture de la session session =sessionFactory.openSession(); // Creation d'un user tx = session.beginTransaction(); org.apache.log4j.BasicConfigurator.configure(); Annee util1=new Annee(); // on peuple l'objet Annee // mais pas la clé primaire, qui nous sera retournée par session.save(); System.out.println("rrrr"); util1.setAn (2005); //util1.setPeriodes (null); session.save(util1); tx.commit(); } catch (Exception e) { if (tx!=null) tx.rollback(); throw e; } finally { session.close(); } } }
thank you in advance
Riyad KallaMemberMoving to OT > Soft Dev
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)