Hi,
in my database i have 3 Tables :
sectors (PK : sector_id)
projects(PK : project_id)
projects_has_sectors(FK : sector_id , FK : project_id)
PK = primary Key, FK = Foreignkey
to modell a many-to-many relationship. i generated the needed domain code files and the *hbm.xml files with hibernate tools in eclipse. the code generation for many-to-many works fine as the <many-to-many> tag for both sectors and projects are generated. the domain code for projects_has_sectors is not generated, which is correct.
so i tried to in insert a new relationship by calling this code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
int id = 4;
Sectors aSector = (Sectors)session.get(Sectors.class,new Integer(id));
int pid = 3;
Projects aProject = (Projects)session.get(Projects.class,new Integer(pid));
System.out.print("Sector name :" +aSector.getSectorname() );
System.out.print("Project name :" +aProject.getDescription());
aProject.getSectorses().add(aSector);
session.saveOrUpdate(aProject);
session.getTransaction().commit();
the problem is during execution the many-to-many table doesnt get updated. and there are no exceptions at all. what is my mistake ?
thank you in advance.
|