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: bidirectional ManyToMany?
PostPosted: Tue Apr 24, 2007 2:22 pm 
Newbie

Joined: Wed Mar 28, 2007 2:51 pm
Posts: 16
Hi,
I set up two classes like in the documentation example in section 2.2.5.3.3.1. However, when I have a handle to a child object, the parent relation Set is empty. I do not explicitly set this relation, but expect it to be populated for me.

There is a join table and I use this on the parent side (ReportModel):


@ManyToMany(
targetEntity=mil.darpa.tn.model.EventModel.class,
fetch=FetchType.EAGER,
cascade={CascadeType.PERSIST, CascadeType.MERGE}
)
@JoinTable(
name="reports_events",
joinColumns={@JoinColumn(name="reports_id")},
inverseJoinColumns={@JoinColumn(name="events_id")}
)
public Set<EventModel> getEvents() {
return events;
}


And this on the child side (EventModel):

@ManyToMany(
cascade={CascadeType.PERSIST, CascadeType.MERGE},
mappedBy="events",
targetEntity=mil.darpa.tn.model.ReportModel.class
)
public Set<ReportModel> getReports() {
return reports;
}

I see the join table, but for the child object, its getReports() is always empty when I am expecting it to be filled with inverse relations.

What am I missing?

Thank you!
Darren


Top
 Profile  
 
 Post subject: Possible problems...
PostPosted: Tue Apr 24, 2007 4:48 pm 
Beginner
Beginner

Joined: Tue Apr 24, 2007 2:03 pm
Posts: 23
There are a few things that could cause this...one, there is no data in the tables (probably unlikely in your case), or you haven't defined your foreign key relationships on the tables.

It might help if you provide the mapping files.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 24, 2007 5:14 pm 
Newbie

Joined: Wed Mar 28, 2007 2:51 pm
Posts: 16
Hi,
Thanks for the response. I guess there are no mapping files since I am using hibernate annotations?

I have 3 tables that come out of it (I auto generate using hibernatetool).

--
reports

reports_events (reports_id, events_id)

events

--
Now, I save a report fine and its children of events also save, and the relation is held in reports_events.

I assumed that the table reports_events would join for both directions, so no "events_reports" table is needed because I am not explicitly setting that relation, only providing the methods.

Do I need a @Join annotation on the events to tell hibernate how to load the report objects (that refer to it) when it is loaded without me having to do it?

I'm a bit new to this, so maybe I missed something. I followed the example precisely.

Darren


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.