Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] loading collection problem

Hi Leon,

What SQL is your query producing? If you run the SQL against your database, does it return a result?

To see the SQL, you can increase the logging level. I suggest using the maximum logging level when debugging. To do that, specify the persistence unit property in your persistence.xml

<property name="eclipselink.logging.level" value="FINEST"/>

-Tom

Leon Derks wrote:
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

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top