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
|