• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown

Problem with OneToMany bidirectional

Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

@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},
public Set<Map> getWorkspaceMaps() {
return maps;

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

@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;

@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)
@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;

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

public Map getLayerMap() {
return (Map) this.map;

public void setLayerMap(Map map) {
this.map = map;
Don't count your weasels before they've popped. And now for a mulberry bush related tiny ad:
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic