Lots of searching in various resources havn't solved this issue for me so here goes..:
Oracle 10 running ojdbc14.jar
Basically, I have two entities, let's call them PERSON and PERSON_METADATA. They have a bi-directional @OneToOne relation.
Problem: I have 1000 PERSONs and I issue a JPA/HQL query such as: entityManager.createQuery("SELECT p FROM Person p").getResultList();
Looking at the SQL debug output in the log, this simple JPA query performs 1001 SELECTs instead of performing a JOIN (or LEFT JOIN if optional=true).
I've fiddled around with various FetchType.EAGER/LAZY, @LazyToOne, @Fetch(FetchMode.EAGER) etc. settings, but still I always get this 1+n number of queries, regardless of how I annotate the @OneToOne relation.
Any ideas on how to get JPA/Hibernate to EAGER load this using a single JOIN?
AFAIK all your fancy annotation stuff is useless when you explicitly code your query.
if you would just use em.find(Person.class, Id) your annotation setting should work
but if you hardcode your query, you must explicitly use a fetch statement like:
from Person p inner join fetch p.metadata