I am trying to make a web application using Netbeans 6.5, MySQL 5.1, JSF, hibernate 3.2 and GlassFish. I want to insert the contents of a form in the database; it works fine when the table doesn't have foreign keys but it doesn't work when they do have them. I tried using Hibernate, and also using an SQL query directly, but it can't get it to work.
public String ok_action() {
try {
String m = module.getValue().toString();
Module mod = new Module(m, null, null, null);
String nmp = ens.getValue().toString();
Enseignant en = new Enseignant(null, null, null, null, null, null, null, null, nmp, null, null, null, null);
Formation f = new Formation();
f = this.getApplicationBean1().getform();
Session sess = null;
sess = HibernateUtil.currentSession();
Transaction tx = sess.beginTransaction();
CoursAcc ca = new CoursAcc();
ca.setEnseignant(en);
ca.setFormation(f);
ca.setModule(mod);
sess.save(ca);
sess.save(f);
tx.commit();
this.getApplicationBean1().setform(null);
} catch (Exception e) {
System.out.println(e.getMessage());
}
return null;
}