This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Problem with OneToMany bidirectional Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem with OneToMany bidirectional " Watch "Problem with OneToMany bidirectional " New topic

Problem with OneToMany bidirectional

Laura Barroso
Ranch Hand

Joined: Sep 21, 2009
Posts: 30
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);

public void setLayerMap(Map map) { = map;
jQuery in Action, 3rd edition
subject: Problem with OneToMany bidirectional
It's not a secret anymore!