-->
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.  [ 1 post ] 
Author Message
 Post subject: ManyToMany: list with duplicates, doesn't update collection
PostPosted: Tue Aug 21, 2007 4:36 am 
Newbie

Joined: Sat Jan 14, 2006 8:03 pm
Posts: 18

Hibernate version - 3.2.1
Database - mySql 5



Application.java

@Entity
@Table(name = "applications")

private Set<Place> places;

@ManyToMany(
targetEntity=com.myco.myapp.model.Place.class,
cascade={CascadeType.ALL},
fetch = FetchType.EAGER
)
@JoinTable(
name="applicationsplaces",
joinColumns={@JoinColumn(name="idApplication")},
inverseJoinColumns={@JoinColumn(name="idPlace")}
)
public Set<Place> getPlaces(){
return places;
}

Place.java
@Entity
@Table(name = "places")

@ManyToMany(
cascade={CascadeType.ALL},
mappedBy="places",
targetEntity=Application.class
)
public Set<Application> getApplications() {
return applications;
}



I am using Spring and Spring MVC (appfuse). My problems:

1. When I list Applications, a record appears for every Place associated with that Application in the applicationsplaces table. If 'app 1' has two Places associated with it, it appears twice. If it has 3, it appears 3 times. It's as if Hibernate were performing a JOIN with an incorrect WHERE ...

In my Spring Controller I am doing nothing more than call the getAll() method of my ApplicationManager class, which is a simple GenericDaoHibernate. When I debug, the getAll() method returns duplicate records, so it's a Hibernate issue, not a page-rendering issue.

2. When saving a new Application the Places are saved. But when updating an Application no changes are made to Places. Again, I am using the save() method of the GenericDaoHibernate class. I have set CascadeType to ALL ... what else do I need to do?

Many thanks!
Bob


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

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.