-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: many-to-many mapping not working but no exceptions
PostPosted: Wed Nov 22, 2006 6:12 am 
Newbie

Joined: Wed Nov 22, 2006 4:45 am
Posts: 3
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.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 22, 2006 6:52 am 
Newbie

Joined: Wed Nov 22, 2006 4:45 am
Posts: 3
follow up :

i did the same thing for one-to-many mappings, the entries are correctly inserted into table but the foreign keys are all null. that means my foreign keys values are not inserted at all for both many-to-many and one-to-many. how do i fix this? i would be glad to provide more info on the situation

thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 22, 2006 9:47 am 
Newbie

Joined: Wed Nov 22, 2006 4:45 am
Posts: 3
got the answer its because i have inverse="true" on both sides.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.