-->
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.  [ 8 posts ] 
Author Message
 Post subject: mapping table not populated
PostPosted: Sun Jan 13, 2008 1:49 pm 
Newbie

Joined: Sun Jan 13, 2008 1:13 pm
Posts: 9
The entities on both sides of the relationship get data in their tables, but the mapping table remains empty. I don't see anything wrong, so I'm hoping someone here will.

The entities are Person and Circle and can be found here:
http://gifttracker.googlecode.com/svn/t ... ircle.java
http://gifttracker.googlecode.com/svn/t ... erson.java

If nothing is wrong with the entities, perhaps something is wrong with how they get persisted. That place, which correctly saves the entities but not their mapping, is here:
http://gifttracker.googlecode.com/svn/t ... eImpl.java

If you look at createAndJoinCircle, that is where the relevant code is. Here is the snippet which does the work:
Circle c = inner.get().createCircle(loggedInUser, name, password);
inner.get().joinCircle(loggedInUser, c);

If I step through in debug mode, the Person does have the circle instance in its 'circles' set right before it's merged. I've also tried adding the person to the circle, but that didn't help.

Thanks for any ideas,
Brian


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 13, 2008 6:01 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Could you post the mapping file, to see if the many-to-many relationship is generated correctly?

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 13, 2008 7:40 pm 
Newbie

Joined: Sun Jan 13, 2008 1:13 pm
Posts: 9
What do you mean? The relationship is defined in the classes, with annotations. Perhaps Hibernate can generate some "mapping file" I'm not aware of? Explain further please.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 14, 2008 11:56 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
No, I am sorry. With annotations you don't need the mapping files. It is not like XDoclet.
Unfortunately I can't help you here, until I learn a little more about annotations myself.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 15, 2008 6:54 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

Do you have any CASCADE attribute set on the @ManyToMany annotation, like below ?

Code:

    @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinTable(name = "course_student",
                joinColumns = @JoinColumn(name = "course_id", referencedColumnName = "course_id"),
                inverseJoinColumns = @JoinColumn(name = "student_id", referencedColumnName = "student_id"))   
    public Set<Student> getStudents() {       
        return mEnrolledStudents;
    }


Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 15, 2008 8:55 am 
Newbie

Joined: Sun Jan 13, 2008 1:13 pm
Posts: 9
No, I have no cascade attributes. However, in my case I first make sure both entities are persisted and only then do I merge the entity which references the other in its collection. That is, by persisting each entity myself, cascade isn't needed, no?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 21, 2008 11:49 am 
Senior
Senior

Joined: Tue Mar 09, 2004 2:38 pm
Posts: 141
Location: Lowell, MA USA
Hi Brian,

I am seeing the same problem with my application as well. My annotation mappings are similar to yours, and I am not seeing the join tables populated. Oddly enough, when I load the entity, the related entities load just fine, even though there's not data in the join table. I'm stumped.

Ryan-

_________________
Ryan J. McDonough
http://damnhandy.com

Please remember to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 1:25 am 
Newbie

Joined: Sun Jan 13, 2008 1:13 pm
Posts: 9
I tried upgrading to the latest versions of hibernate (core, annotations, entity manager), and this problem seems to be fixed. I hope you have the same experience.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.