This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with OneToMany bidirectional

 
Laura Barroso
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a OneToMany bidirectional relationship, from Workspace to Map, and Map to Layers…the relation seems to work just fine between Workspace and Map, however when I try to load the Layers that are contains in Map it only load one Layer… what could be the problem???
This is my code:

@Entity
@Table(name = "workspaces" ,
uniqueConstraints = {@UniqueConstraint(columnNames = {"name"} ) })
@SequenceGenerator(name = "workspace_sequence", sequenceName = "workspace_id_seq")
public class Workspace extends EntityBean<Integer> implements IWorkspace {
private Set<Map> maps = new HashSet<Map>();
@OneToMany( mappedBy="mapWorkspace", cascade={ CascadeType.ALL},
fetch=FetchType.EAGER)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
public Set<Map> getWorkspaceMaps() {
return maps;
}

public void setWorkspaceMaps(Set<Map> maps) {
this.maps = maps;
}
….
}

@Entity
@Table(name = "maps")
@SequenceGenerator(name = "map_sequence", sequenceName = "map_id_seq")
public class Map extends EntityBean<Integer> implements IMap {
private SortedSet<MapLayer> layerList = new TreeSet<MapLayer>();
private Workspace workspace;

@ManyToOne
@JoinColumn(name = "workspace_id", referencedColumnName="workspace_id")
public Workspace getMapWorkspace() {
return this.workspace;
}

public void setMapWorkspace(Workspace workspace) {
this.workspace = workspace;
}

@OneToMany( mappedBy = "layerMap", cascade={CascadeType.ALL} ,
fetch = FetchType.EAGER )
@OptimisticLock(excluded = true)
@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@Sort(comparator = org.desoft.geo.entity.LayerPosComparator.class,
type = SortType.COMPARATOR)
public SortedSet<MapLayer> getMapLayers() {
return layerList;
}

public void setMapLayers(SortedSet<MapLayer> layers) {
this.layerList = layers;
}
}

@Entity
@Table(name = "layers")
@SequenceGenerator(name = "layer_sequence", sequenceName = "layer_id_seq")
@Inheritance(strategy=InheritanceType.JOINED)
public class MapLayer extends MapElementBase<Integer> implements IMapLayer, Serializable {

@ManyToOne
@JoinColumn(name="map_id",referencedColumnName="map_id")
public Map getLayerMap() {
return (Map) this.map;
}

public void setLayerMap(Map map) {
this.map = map;
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic