[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] loading collection problem
|
Hello
Thanks for the answer on my previous question. That works well!
But now I have another problem.
I want to load an object with a collection that may be empty.
For example my Lamp object has a @ManyToMany relation with Gear.
public class Lamp extends Product {
@ManyToMany
@JoinTable(name="PLI_LAMP_GEAR", joinColumns =
@JoinColumn(name="lamp_id", referencedColumnName = "ID"),
inverseJoinColumns = @JoinColumn(name="gear_id", referencedColumnName =
"ID"))
private List<Gear> gears = new ArrayList<Gear>()
}
public class Gear extends Product {
}
In my situation, the Lamp has no Gears, so the join table is empty for
this lamp.
But when I try to load the Lamp it returns nothing. I want it to return
a Lamp (with name, description etc) and an empty collection of Gears.
This is my named query: "select l from Lamp l left join fetch l.gears
where l.id = :lampId"
I tried several queries, but always get the message:
"javax.persistence.NoResultException: getSingleResult() did not retrieve
any entities."
Am I doing something wrong?
greetings,
Leon