Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] IndirectSet cannot be cast to java.util.TreeSet

Hi all,

I've got an error when I look up my lazy loaded children of one of my pojos:

java.lang.ClassCastException: org.eclipse.persistence.indirection.IndirectSet cannot be cast to java.util.TreeSet

Ok, the thing has something to do with the lazy loading technology in EclipseLink/TopLink... if i have an entity like this:

@Entity
class Entity {

@OneToMany (mappedBy = "entity", fetch=FetchType.LAZY, cascade = {CascadeType.ALL})
private Set<Child> childrens = new TreeSet<Child>();

public void setChildrens(Set<Child> childrens) { this.childrens = childrens }

public Set<Child> getChildrens() { return this.childrens }

	public Child getNextChild() {
		return this. childrens.size() > 0 ? ((TreeSet<Child>) this. childrens).last() : null;
	}
... 
}

If I now find all entities of Entity and call getNextChild(), I will get the error. It seems that EclipseLink will pass a IndirectSet object into my childrens set and then I can not cast it anymore. The indirect set handles somehow the lazy load technique.... so what to do?

I tried this:
public void setChildrens(Set<Child> childrens) { this.childrens = new TreeSet<Child>(childrens); }

but this does not work either. It seems, that EclipseLink is using reflection to pass the IndiretSet into my set property.

I my assumptions are correct, what is to do if want to use lazy loading, a TreeSet (for sorting purposes--see .last() above) and the Set property of my Entity class interface should be remain java.uti.Set?

Thank you for help!

Martin.



Back to the top